Skip to content

Commit e33d59c

Browse files
committed
Review cleanups.
1 parent de22dbe commit e33d59c

2 files changed

Lines changed: 35 additions & 23 deletions

File tree

src/sniffer.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
#include <wolfssl/wolfcrypt/async.h>
3333
#endif
3434

35+
/* Build Options:
36+
* WOLFSSL_SNIFFER_NO_RECOVERY: Do not track missed data count.
37+
*/
38+
39+
3540
/* xctime */
3641
#ifndef XCTIME
3742
#define XCTIME ctime
@@ -693,9 +698,7 @@ static int GetDevId(void)
693698

694699
void ssl_InitSniffer(void)
695700
{
696-
int devId;
697-
698-
devId = GetDevId();
701+
int devId = GetDevId();
699702

700703
#ifdef WOLFSSL_ASYNC_CRYPT
701704
if (wolfAsync_DevOpen(&devId) < 0) {
@@ -711,16 +714,15 @@ void ssl_InitSniffer(void)
711714

712715
void ssl_InitSniffer_ex2(int threadNum)
713716
{
714-
int devId;
715-
716-
devId = GetDevId();
717+
int devId = GetDevId();
717718

718719
#ifdef WOLFSSL_ASYNC_CRYPT
719720
#ifndef WC_NO_ASYNC_THREADING
720-
if (wolfAsync_DevOpenThread(&devId,&threadNum) < 0) {
721+
if (wolfAsync_DevOpenThread(&devId,&threadNum) < 0)
721722
#else
722-
if (wolfAsync_DevOpen(&devId) < 0) {
723+
if (wolfAsync_DevOpen(&devId) < 0)
723724
#endif
725+
{
724726
fprintf(stderr, "Async device open failed\nRunning without async\n");
725727
devId = INVALID_DEVID;
726728
}
@@ -6518,6 +6520,7 @@ static int ssl_DecodePacketInternal(const byte* packet, int length, int isChain,
65186520
SnifferSession* session = NULL;
65196521
void* vChain = NULL;
65206522
word32 chainSz = 0;
6523+
65216524
if (isChain) {
65226525
#ifdef WOLFSSL_SNIFFER_CHAIN_INPUT
65236526
struct iovec* chain;

sslSniffer/sslSnifferTest/snifftest.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@
3434
#include <wolfssl/wolfcrypt/memory.h>
3535
#endif
3636

37+
#ifdef THREADED_SNIFFTEST
38+
#include <pthread.h>
39+
#endif
40+
41+
42+
/* Build Options:
43+
* THREADED_SNIFFTEST: Enable threaded version of the sniffer test
44+
*/
45+
46+
47+
/* For windows tests force sniffer build option on */
3748
#ifdef _WIN32
3849
#define WOLFSSL_SNIFFER
3950
#endif
4051

41-
#ifdef THREADED_SNIFFTEST
42-
#include <pthread.h>
43-
#endif
4452

4553
#ifndef WOLFSSL_SNIFFER
4654
#ifndef NO_MAIN_DRIVER
@@ -497,7 +505,7 @@ static THREAD_LS_T SnifferPacket asyncQueue[WOLF_ASYNC_MAX_PENDING];
497505
static int SnifferAsyncQueueAdd(int lastRet, void* chain, int chainSz,
498506
int isChain, int packetNumber)
499507
{
500-
int ret = MEMORY_E, i, length;
508+
int ret, i, length;
501509
byte* packet;
502510

503511
#ifdef WOLFSSL_SNIFFER_CHAIN_INPUT
@@ -516,6 +524,7 @@ static int SnifferAsyncQueueAdd(int lastRet, void* chain, int chainSz,
516524
}
517525

518526
/* find first free idx */
527+
ret = MEMORY_E;
519528
for (i=0; i<WOLF_ASYNC_MAX_PENDING; i++) {
520529
if (asyncQueue[i].packet == NULL) {
521530
if (ret == MEMORY_E) {
@@ -647,9 +656,7 @@ static int ssl_Init_SnifferWorker(SnifferWorker* worker, int port,
647656

648657
worker->head = (SnifferPacket*)XMALLOC(sizeof(SnifferPacket), NULL,
649658
DYNAMIC_TYPE_TMP_BUFFER);
650-
651659
if (worker->head == NULL) {
652-
XFREE(worker->head, NULL, DYNAMIC_TYPE_TMP_BUFFER);
653660
return MEMORY_E;
654661
}
655662

@@ -670,6 +677,7 @@ static void ssl_Free_SnifferWorker(SnifferWorker* worker)
670677

671678
if (worker->head) {
672679
XFREE(worker->head, NULL, DYNAMIC_TYPE_TMP_BUFFER);
680+
worker->head = NULL;
673681
}
674682
}
675683

@@ -680,13 +688,16 @@ static int SnifferWorkerPacketAdd(SnifferWorker* worker, int lastRet,
680688

681689
newEntry = (SnifferPacket*)XMALLOC(sizeof(SnifferPacket), NULL,
682690
DYNAMIC_TYPE_TMP_BUFFER);
683-
691+
if (newEntry == NULL) {
692+
return MEMORY_E;
693+
}
694+
XMEMSET(newEntry, 0, sizeof(SnifferPacket));
684695
newEntry->packet = (byte*)XMALLOC(length, NULL, DYNAMIC_TYPE_TMP_BUFFER);
685-
if (newEntry == NULL || newEntry->packet == NULL) {
686-
XFREE(newEntry->packet, NULL, DYNAMIC_TYPE_TMP_BUFFER);
696+
if (newEntry->packet == NULL) {
687697
XFREE(newEntry, NULL, DYNAMIC_TYPE_TMP_BUFFER);
688698
return MEMORY_E;
689699
}
700+
690701
/* Set newEntry fields to input values */
691702
XMEMCPY(newEntry->packet, packet, length);
692703
newEntry->length = length;
@@ -787,23 +798,19 @@ static int DecodePacket(byte* packet, int length, int packetNumber, char err[])
787798
}
788799

789800
#elif defined(WOLFSSL_SNIFFER_CHAIN_INPUT) && \
790-
defined(WOLFSSL_SNIFFER_STORE_DATA_CB)
801+
defined(WOLFSSL_SNIFFER_STORE_DATA_CB)
791802
ret = ssl_DecodePacketWithChainSessionInfoStoreData(chain, chainSz,
792803
&data, &sslInfo, err);
793804
#elif defined(WOLFSSL_SNIFFER_CHAIN_INPUT)
794805
(void)sslInfo;
795806
ret = ssl_DecodePacketWithChain(chain, chainSz, &data, err);
796-
#else
797-
#if defined(WOLFSSL_SNIFFER_STORE_DATA_CB)
807+
#elif defined(WOLFSSL_SNIFFER_STORE_DATA_CB)
798808
ret = ssl_DecodePacketWithSessionInfoStoreData(packet,
799809
length, &data, &sslInfo, err);
800810
#else
801811
ret = ssl_DecodePacketWithSessionInfo(packet, length, &data,
802812
&sslInfo, err);
803813
#endif
804-
(void)chain;
805-
(void)chainSz;
806-
#endif
807814

808815
if (ret < 0) {
809816
printf("ssl_Decode ret = %d, %s on packet number %d\n", ret, err,
@@ -823,6 +830,8 @@ defined(WOLFSSL_SNIFFER_STORE_DATA_CB)
823830
}
824831

825832
(void)isChain;
833+
(void)chain;
834+
(void)chainSz;
826835

827836
return hadBadPacket;
828837
}

0 commit comments

Comments
 (0)