From 2622006faa66e9b3ac86bce47f7825f60870cac4 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 21 Mar 2019 14:22:04 +0100 Subject: [PATCH] stream: minor test cleanups --- src/stream-tcp-reassemble.c | 84 +++++++++++-------------------------- src/stream-tcp.c | 12 +++--- 2 files changed, 31 insertions(+), 65 deletions(-) diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c index 0559e11786..a4954e14a9 100644 --- a/src/stream-tcp-reassemble.c +++ b/src/stream-tcp-reassemble.c @@ -2164,6 +2164,7 @@ static int StreamTcpReassembleTest37(void) uint8_t packet[1460] = ""; PacketQueue pq; ThreadVars tv; + memset(&tv, 0, sizeof (ThreadVars)); Packet *p = PacketGetFromAlloc(); FAIL_IF(unlikely(p == NULL)); @@ -2712,10 +2713,8 @@ static int StreamTcpReassembleTest39 (void) static int StreamTcpReassembleTest40 (void) { - int ret = 0; Packet *p = PacketGetFromAlloc(); - if (unlikely(p == NULL)) - return 0; + FAIL_IF_NULL(p); Flow *f = NULL; TCPHdr tcph; TcpSession ssn; @@ -2728,7 +2727,8 @@ static int StreamTcpReassembleTest40 (void) StreamTcpInitConfig(TRUE); StreamTcpUTSetupSession(&ssn); - TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL); + TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(&tv); + FAIL_IF_NULL(ra_ctx); uint8_t httpbuf1[] = "P"; uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */ @@ -2748,8 +2748,7 @@ static int StreamTcpReassembleTest40 (void) ssn.client.isn = 9; f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 200, 220); - if (f == NULL) - goto end; + FAIL_IF_NULL(f); f->protoctx = &ssn; f->proto = IPPROTO_TCP; p->flow = f; @@ -2760,19 +2759,13 @@ static int StreamTcpReassembleTest40 (void) tcph.th_flags = TH_ACK|TH_PUSH; p->tcph = &tcph; p->flowflags = FLOW_PKT_TOSERVER; - p->payload = httpbuf1; p->payload_len = httplen1; ssn.state = TCP_ESTABLISHED; + TcpStream *s = &ssn.client; + SCLogDebug("1 -- start"); + FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1); - TcpStream *s = NULL; - s = &ssn.client; - - FLOWLOCK_WRLOCK(f); - if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) { - printf("failed in segments reassembly, while processing toserver packet (1): "); - goto end; - } p->flowflags = FLOW_PKT_TOCLIENT; p->payload = httpbuf2; p->payload_len = httplen2; @@ -2780,11 +2773,8 @@ static int StreamTcpReassembleTest40 (void) tcph.th_ack = htonl(11); s = &ssn.server; ssn.server.last_ack = 11; - - if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) { - printf("failed in segments reassembly, while processing toserver packet (3): "); - goto end; - } + SCLogDebug("2 -- start"); + FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1); p->flowflags = FLOW_PKT_TOSERVER; p->payload = httpbuf3; @@ -2793,11 +2783,8 @@ static int StreamTcpReassembleTest40 (void) tcph.th_ack = htonl(55); s = &ssn.client; ssn.client.last_ack = 55; - - if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) { - printf("failed in segments reassembly, while processing toserver packet (5): "); - goto end; - } + SCLogDebug("3 -- start"); + FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1); p->flowflags = FLOW_PKT_TOCLIENT; p->payload = httpbuf2; @@ -2806,11 +2793,8 @@ static int StreamTcpReassembleTest40 (void) tcph.th_ack = htonl(12); s = &ssn.server; ssn.server.last_ack = 12; - - if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) { - printf("failed in segments reassembly, while processing toserver packet (6): "); - goto end; - } + SCLogDebug("4 -- start"); + FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1); /* check is have the segment in the list and flagged or not */ TcpSegment *seg = RB_MIN(TCPSEG, &ssn.client.seg_tree); @@ -2824,11 +2808,8 @@ static int StreamTcpReassembleTest40 (void) tcph.th_ack = htonl(100); s = &ssn.client; ssn.client.last_ack = 100; - - if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) { - printf("failed in segments reassembly, while processing toserver packet (10): "); - goto end; - } + SCLogDebug("5 -- start"); + FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1); p->flowflags = FLOW_PKT_TOCLIENT; p->payload = httpbuf2; @@ -2837,11 +2818,8 @@ static int StreamTcpReassembleTest40 (void) tcph.th_ack = htonl(13); s = &ssn.server; ssn.server.last_ack = 13; - - if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) { - printf("failed in segments reassembly, while processing toserver packet (11): "); - goto end; - } + SCLogDebug("6 -- start"); + FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1); p->flowflags = FLOW_PKT_TOSERVER; p->payload = httpbuf5; @@ -2850,11 +2828,8 @@ static int StreamTcpReassembleTest40 (void) tcph.th_ack = htonl(145); s = &ssn.client; ssn.client.last_ack = 145; - - if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) { - printf("failed in segments reassembly, while processing toserver packet (14): "); - goto end; - } + SCLogDebug("7 -- start"); + FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1); p->flowflags = FLOW_PKT_TOCLIENT; p->payload = httpbuf2; @@ -2863,25 +2838,16 @@ static int StreamTcpReassembleTest40 (void) tcph.th_ack = htonl(16); s = &ssn.server; ssn.server.last_ack = 16; + SCLogDebug("8 -- start"); + FAIL_IF(StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1); + FAIL_IF(f->alproto != ALPROTO_HTTP); - if (StreamTcpReassembleHandleSegment(&tv, ra_ctx, &ssn, s, p, &pq) == -1) { - printf("failed in segments reassembly, while processing toserver packet (15): "); - goto end; - } - if (f->alproto != ALPROTO_HTTP) { - printf("app layer proto has not been detected (18): "); - goto end; - } - - ret = 1; -end: StreamTcpUTClearSession(&ssn); StreamTcpReassembleFreeThreadCtx(ra_ctx); StreamTcpFreeConfig(TRUE); SCFree(p); - FLOWLOCK_UNLOCK(f); UTHFreeFlow(f); - return ret; + PASS; } /** \test Test the memcap incrementing/decrementing and memcap check */ @@ -3007,7 +2973,7 @@ static int StreamTcpReassembleTest47 (void) memset(&tv, 0, sizeof (ThreadVars)); StreamTcpInitConfig(TRUE); StreamTcpUTSetupSession(&ssn); - TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(NULL); + TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx(&tv); uint8_t httpbuf1[] = "GET /EVILSUFF HTTP/1.1\r\n\r\n"; uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */ diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 0d5dcd0df0..7c0ff47021 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -8313,7 +8313,7 @@ static int StreamTcpTest18 (void) TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); if (unlikely(p == NULL)) - return 0; + return 0; IPV4Hdr ipv4h; int ret = 0; @@ -8362,7 +8362,7 @@ static int StreamTcpTest19 (void) TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); if (unlikely(p == NULL)) - return 0; + return 0; IPV4Hdr ipv4h; int ret = 0; @@ -8414,7 +8414,7 @@ static int StreamTcpTest20 (void) TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); if (unlikely(p == NULL)) - return 0; + return 0; IPV4Hdr ipv4h; int ret = 0; @@ -8466,7 +8466,7 @@ static int StreamTcpTest21 (void) TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); if (unlikely(p == NULL)) - return 0; + return 0; IPV4Hdr ipv4h; int ret = 0; @@ -8518,7 +8518,7 @@ static int StreamTcpTest22 (void) TcpStream stream; Packet *p = SCMalloc(SIZE_OF_PACKET); if (unlikely(p == NULL)) - return 0; + return 0; IPV4Hdr ipv4h; int ret = 0; @@ -8637,6 +8637,7 @@ static int StreamTcpTest24(void) TCPHdr tcph; uint8_t packet[1460] = ""; ThreadVars tv; + memset(&tv, 0, sizeof (ThreadVars)); PacketQueue pq; memset(&pq,0,sizeof(PacketQueue)); @@ -8645,7 +8646,6 @@ static int StreamTcpTest24(void) memset(p, 0, SIZE_OF_PACKET); memset(&f, 0, sizeof (Flow)); - memset(&tv, 0, sizeof (ThreadVars)); memset(&tcph, 0, sizeof (TCPHdr)); FLOW_INITIALIZE(&f); ssn.client.os_policy = OS_POLICY_BSD;