unittest: recycle packet before exit

To avoid an issue with flow validation, we need to recycle the packet
before cleaning the flow.
pull/506/head
Eric Leblond 12 years ago committed by Victor Julien
parent d292f1a529
commit c5bd04f102

@ -40,6 +40,10 @@
#include "alert-unified2-alert.h" #include "alert-unified2-alert.h"
#include "decode-ipv4.h" #include "decode-ipv4.h"
#include "host.h"
#include "util-profiling.h"
#include "decode.h"
#include "util-error.h" #include "util-error.h"
#include "util-debug.h" #include "util-debug.h"
#include "util-time.h" #include "util-time.h"
@ -1162,39 +1166,40 @@ static int Unified2Test01 (void) {
DecodeEthernet(&tv, &dtv, p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq); DecodeEthernet(&tv, &dtv, p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq);
FlowShutdown();
oc = Unified2AlertInitCtx(NULL); oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) { if (oc == NULL) {
SCFree(p); goto end;
return 0;
} }
lf = (LogFileCtx *)oc->data; lf = (LogFileCtx *)oc->data;
if(lf == NULL) { if(lf == NULL) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadInit(&tv, oc, &data); ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == TM_ECODE_FAILED) { if(ret == TM_ECODE_FAILED) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2Alert(&tv, p, data, &pq, NULL); ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) { if(ret == TM_ECODE_FAILED) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadDeinit(&tv, data); ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == -1) { if(ret == -1) {
SCFree(p); goto end;
return 0;
} }
Unified2AlertDeInitCtx(oc); Unified2AlertDeInitCtx(oc);
PACKET_CLEANUP(p); PACKET_RECYCLE(p);
SCFree(p); SCFree(p);
FlowShutdown();
return 1; return 1;
end:
PACKET_RECYCLE(p);
SCFree(p);
FlowShutdown();
return 0;
} }
/** /**
@ -1248,39 +1253,39 @@ static int Unified2Test02 (void) {
DecodeEthernet(&tv, &dtv, p, raw_ipv6_tcp, sizeof(raw_ipv6_tcp), &pq); DecodeEthernet(&tv, &dtv, p, raw_ipv6_tcp, sizeof(raw_ipv6_tcp), &pq);
FlowShutdown();
oc = Unified2AlertInitCtx(NULL); oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) { if (oc == NULL) {
SCFree(p); goto end;
return 0;
} }
lf = (LogFileCtx *)oc->data; lf = (LogFileCtx *)oc->data;
if(lf == NULL) { if(lf == NULL) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadInit(&tv, oc, &data); ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1) { if(ret == -1) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2Alert(&tv, p, data, &pq, NULL); ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) { if(ret == TM_ECODE_FAILED) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadDeinit(&tv, data); ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == -1) { if(ret == -1) {
SCFree(p); goto end;
return 0;
} }
Unified2AlertDeInitCtx(oc); Unified2AlertDeInitCtx(oc);
PACKET_CLEANUP(p); PACKET_RECYCLE(p);
SCFree(p); SCFree(p);
FlowShutdown();
return 1; return 1;
end:
PACKET_RECYCLE(p);
SCFree(p);
FlowShutdown();
return 0;
} }
@ -1319,6 +1324,7 @@ static int Unified2Test03 (void) {
0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65, 0x74,
0x0d, 0x0a}; 0x0d, 0x0a};
Packet *p = PacketGetFromAlloc(); Packet *p = PacketGetFromAlloc();
Packet *pkt;
if (unlikely(p == NULL)) if (unlikely(p == NULL))
return 0; return 0;
int ret; int ret;
@ -1340,45 +1346,52 @@ static int Unified2Test03 (void) {
DecodeEthernet(&tv, &dtv, p, raw_gre, sizeof(raw_gre), &pq); DecodeEthernet(&tv, &dtv, p, raw_gre, sizeof(raw_gre), &pq);
FlowShutdown();
oc = Unified2AlertInitCtx(NULL); oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) { if (oc == NULL) {
SCFree(p); goto end;
return 0;
} }
lf = (LogFileCtx *)oc->data; lf = (LogFileCtx *)oc->data;
if(lf == NULL) { if(lf == NULL) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadInit(&tv, oc, &data); ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1) { if(ret == -1) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2Alert(&tv, p, data, &pq, NULL); ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) { if(ret == TM_ECODE_FAILED) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadDeinit(&tv, data); ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == -1) { if(ret == -1) {
SCFree(p); goto end;
return 0;
} }
Unified2AlertDeInitCtx(oc); Unified2AlertDeInitCtx(oc);
Packet *pkt = PacketDequeue(&pq); pkt = PacketDequeue(&pq);
while (pkt != NULL) { while (pkt != NULL) {
PACKET_RECYCLE(pkt);
SCFree(pkt); SCFree(pkt);
pkt = PacketDequeue(&pq); pkt = PacketDequeue(&pq);
} }
PACKET_CLEANUP(p); PACKET_RECYCLE(p);
SCFree(p); SCFree(p);
FlowShutdown();
return 1; return 1;
end:
pkt = PacketDequeue(&pq);
while (pkt != NULL) {
PACKET_RECYCLE(pkt);
SCFree(pkt);
pkt = PacketDequeue(&pq);
}
PACKET_RECYCLE(p);
SCFree(p);
FlowShutdown();
return 0;
} }
/** /**
@ -1426,39 +1439,39 @@ static int Unified2Test04 (void) {
DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), &pq); DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), &pq);
FlowShutdown();
oc = Unified2AlertInitCtx(NULL); oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) { if (oc == NULL) {
SCFree(p); goto end;
return 0;
} }
lf = (LogFileCtx *)oc->data; lf = (LogFileCtx *)oc->data;
if(lf == NULL) { if(lf == NULL) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadInit(&tv, oc, &data); ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1) { if(ret == -1) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2Alert(&tv, p, data, &pq, NULL); ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) { if(ret == TM_ECODE_FAILED) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadDeinit(&tv, data); ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == -1) { if(ret == -1) {
SCFree(p); goto end;
return 0;
} }
Unified2AlertDeInitCtx(oc); Unified2AlertDeInitCtx(oc);
PACKET_CLEANUP(p); PACKET_RECYCLE(p);
SCFree(p); SCFree(p);
FlowShutdown();
return 1; return 1;
end:
PACKET_RECYCLE(p);
SCFree(p);
FlowShutdown();
return 0;
} }
/** /**
@ -1510,41 +1523,41 @@ static int Unified2Test05 (void) {
DecodeEthernet(&tv, &dtv, p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq); DecodeEthernet(&tv, &dtv, p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq);
FlowShutdown();
p->action = ACTION_DROP; p->action = ACTION_DROP;
oc = Unified2AlertInitCtx(NULL); oc = Unified2AlertInitCtx(NULL);
if (oc == NULL) { if (oc == NULL) {
SCFree(p); goto end;
return 0;
} }
lf = (LogFileCtx *)oc->data; lf = (LogFileCtx *)oc->data;
if(lf == NULL) { if(lf == NULL) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadInit(&tv, oc, &data); ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1) { if(ret == -1) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2Alert(&tv, p, data, &pq, NULL); ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) { if(ret == TM_ECODE_FAILED) {
SCFree(p); goto end;
return 0;
} }
ret = Unified2AlertThreadDeinit(&tv, data); ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == TM_ECODE_FAILED) { if(ret == TM_ECODE_FAILED) {
SCFree(p); goto end;
return 0;
} }
Unified2AlertDeInitCtx(oc); Unified2AlertDeInitCtx(oc);
PACKET_CLEANUP(p); PACKET_RECYCLE(p);
SCFree(p); SCFree(p);
FlowShutdown();
return 1; return 1;
end:
PACKET_RECYCLE(p);
SCFree(p);
FlowShutdown();
return 0;
} }
/** /**

@ -42,6 +42,10 @@
#include "util-debug.h" #include "util-debug.h"
#include "util-print.h" #include "util-print.h"
#include "pkt-var.h"
#include "util-profiling.h"
#include "host.h"
/** /**
* \brief Get variables and do some checks of the embedded IPV6 packet * \brief Get variables and do some checks of the embedded IPV6 packet
@ -387,7 +391,6 @@ static int ICMPV6ParamProbTest01(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p->icmpv6h == NULL) { if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6"); SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@ -416,6 +419,8 @@ static int ICMPV6ParamProbTest01(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -459,7 +464,6 @@ static int ICMPV6PktTooBigTest01(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p->icmpv6h == NULL) { if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6"); SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@ -490,6 +494,8 @@ static int ICMPV6PktTooBigTest01(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -534,7 +540,6 @@ static int ICMPV6TimeExceedTest01(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p->icmpv6h == NULL) { if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6"); SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@ -566,6 +571,8 @@ static int ICMPV6TimeExceedTest01(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -610,7 +617,6 @@ static int ICMPV6DestUnreachTest01(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p->icmpv6h == NULL) { if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6"); SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@ -640,6 +646,8 @@ static int ICMPV6DestUnreachTest01(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -673,7 +681,6 @@ static int ICMPV6EchoReqTest01(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p->icmpv6h == NULL) { if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6"); SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@ -692,6 +699,8 @@ static int ICMPV6EchoReqTest01(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -726,7 +735,6 @@ static int ICMPV6EchoRepTest01(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p->icmpv6h == NULL) { if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6"); SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@ -746,6 +754,8 @@ static int ICMPV6EchoRepTest01(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -786,7 +796,6 @@ static int ICMPV6ParamProbTest02(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p->icmpv6h == NULL) { if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6"); SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@ -808,6 +817,8 @@ static int ICMPV6ParamProbTest02(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -847,7 +858,6 @@ static int ICMPV6PktTooBigTest02(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p->icmpv6h == NULL) { if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6"); SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
@ -863,6 +873,8 @@ static int ICMPV6PktTooBigTest02(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -899,7 +911,6 @@ static int ICMPV6TimeExceedTest02(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (!ENGINE_ISSET_EVENT(p, ICMPV6_PKT_TOO_SMALL)) { if (!ENGINE_ISSET_EVENT(p, ICMPV6_PKT_TOO_SMALL)) {
SCLogDebug("ICMPv6 Error: event packet too small not set"); SCLogDebug("ICMPv6 Error: event packet too small not set");
@ -909,6 +920,8 @@ static int ICMPV6TimeExceedTest02(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -948,7 +961,6 @@ static int ICMPV6DestUnreachTest02(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (!ENGINE_ISSET_EVENT(p, ICMPV6_IPV6_TRUNC_PKT)) { if (!ENGINE_ISSET_EVENT(p, ICMPV6_IPV6_TRUNC_PKT)) {
SCLogDebug("ICMPv6 Error: embedded ipv6 truncated packet event not set"); SCLogDebug("ICMPv6 Error: embedded ipv6 truncated packet event not set");
@ -958,6 +970,8 @@ static int ICMPV6DestUnreachTest02(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -993,7 +1007,6 @@ static int ICMPV6EchoReqTest02(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) { if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
SCLogDebug("ICMPv6 Error: Unknown code event not set"); SCLogDebug("ICMPv6 Error: Unknown code event not set");
@ -1003,6 +1016,8 @@ static int ICMPV6EchoReqTest02(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -1038,7 +1053,6 @@ static int ICMPV6EchoRepTest02(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) { if (!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
SCLogDebug("ICMPv6 Error: Unknown code event not set"); SCLogDebug("ICMPv6 Error: Unknown code event not set");
@ -1048,6 +1062,8 @@ static int ICMPV6EchoRepTest02(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -1086,7 +1102,6 @@ static int ICMPV6PayloadTest01(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p->payload == NULL) { if (p->payload == NULL) {
printf("payload == NULL, expected non-NULL: "); printf("payload == NULL, expected non-NULL: ");
@ -1100,6 +1115,8 @@ static int ICMPV6PayloadTest01(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }

@ -1535,13 +1535,13 @@ int DecodeIPV4DefragTest01(void)
goto end; goto end;
} }
PACKET_CLEANUP(p); PACKET_RECYCLE(tp);
SCFree(tp); SCFree(tp);
end: end:
DefragDestroy(); DefragDestroy();
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
PACKET_CLEANUP(p);
SCFree(p); SCFree(p);
return result; return result;
} }
@ -1667,13 +1667,13 @@ int DecodeIPV4DefragTest02(void)
} }
result = 1; result = 1;
PACKET_CLEANUP(p); PACKET_RECYCLE(tp);
SCFree(tp); SCFree(tp);
end: end:
DefragDestroy(); DefragDestroy();
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
PACKET_CLEANUP(p);
SCFree(p); SCFree(p);
return result; return result;
} }
@ -1826,13 +1826,13 @@ int DecodeIPV4DefragTest03(void)
goto end; goto end;
} }
PACKET_CLEANUP(p); PACKET_RECYCLE(tp);
SCFree(tp); SCFree(tp);
end: end:
DefragDestroy(); DefragDestroy();
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
PACKET_CLEANUP(p);
SCFree(p); SCFree(p);
return result; return result;
} }

@ -41,6 +41,8 @@
#include "util-debug.h" #include "util-debug.h"
#include "util-print.h" #include "util-print.h"
#include "util-unittest.h" #include "util-unittest.h"
#include "util-profiling.h"
#include "host.h"
#define IPV6_EXTHDRS ip6eh.ip6_exthdrs #define IPV6_EXTHDRS ip6eh.ip6_exthdrs
#define IPV6_EH_CNT ip6eh.ip6_exthdrs_cnt #define IPV6_EH_CNT ip6eh.ip6_exthdrs_cnt
@ -738,6 +740,7 @@ static int DecodeIPV6FragTest01 (void) {
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
}; };
Packet *pkt;
Packet *p1 = PacketGetFromAlloc(); Packet *p1 = PacketGetFromAlloc();
if (unlikely(p1 == NULL)) if (unlikely(p1 == NULL))
return 0; return 0;
@ -782,10 +785,16 @@ static int DecodeIPV6FragTest01 (void) {
result = 1; result = 1;
end: end:
PACKET_CLEANUP(p1); PACKET_RECYCLE(p1);
PACKET_CLEANUP(p2); PACKET_RECYCLE(p2);
SCFree(p1); SCFree(p1);
SCFree(p2); SCFree(p2);
pkt = PacketDequeue(&pq);
while (pkt != NULL) {
PACKET_RECYCLE(pkt);
SCFree(pkt);
pkt = PacketDequeue(&pq);
}
DefragDestroy(); DefragDestroy();
FlowShutdown(); FlowShutdown();
return result; return result;
@ -838,7 +847,7 @@ static int DecodeIPV6RouteTest01 (void) {
result = 1; result = 1;
end: end:
PACKET_CLEANUP(p1); PACKET_RECYCLE(p1);
SCFree(p1); SCFree(p1);
FlowShutdown(); FlowShutdown();
return result; return result;

@ -38,6 +38,11 @@
#include "util-unittest.h" #include "util-unittest.h"
#include "util-debug.h" #include "util-debug.h"
#include "pkt-var.h"
#include "util-profiling.h"
#include "host.h"
void DecodeRaw(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq) void DecodeRaw(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
{ {
SCPerfCounterIncr(dtv->counter_raw, tv->sc_perf_pca); SCPerfCounterIncr(dtv->counter_raw, tv->sc_perf_pca);
@ -107,6 +112,7 @@ static int DecodeRawTest01 (void) {
return 1; return 1;
} }
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);
return 0; return 0;
@ -144,13 +150,16 @@ static int DecodeRawTest02 (void) {
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p), NULL); DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p), NULL);
FlowShutdown();
if (p->ip4h == NULL) { if (p->ip4h == NULL) {
printf("expected a valid ipv4 header but it was NULL: "); printf("expected a valid ipv4 header but it was NULL: ");
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return 1; return 1;
} }
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return 0; return 0;
} }
@ -195,6 +204,7 @@ static int DecodeRawTest03 (void) {
} else { } else {
printf("expected IPRAW_INVALID_IPV to be set but it wasn't: "); printf("expected IPRAW_INVALID_IPV to be set but it wasn't: ");
} }
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);
return 1; return 1;

@ -38,6 +38,9 @@
#include "util-debug.h" #include "util-debug.h"
#include "util-optimize.h" #include "util-optimize.h"
#include "flow.h" #include "flow.h"
#include "util-profiling.h"
#include "pkt-var.h"
#include "host.h"
static int DecodeTCPOptions(Packet *p, uint8_t *pkt, uint16_t len) static int DecodeTCPOptions(Packet *p, uint8_t *pkt, uint16_t len)
{ {
@ -319,7 +322,6 @@ static int TCPGetWscaleTest01(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL); DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
FlowShutdown();
if (p->tcph == NULL) { if (p->tcph == NULL) {
printf("tcp packet decode failed: "); printf("tcp packet decode failed: ");
@ -334,6 +336,8 @@ static int TCPGetWscaleTest01(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -364,7 +368,6 @@ static int TCPGetWscaleTest02(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL); DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
FlowShutdown();
if (p->tcph == NULL) { if (p->tcph == NULL) {
printf("tcp packet decode failed: "); printf("tcp packet decode failed: ");
@ -379,6 +382,8 @@ static int TCPGetWscaleTest02(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -408,7 +413,6 @@ static int TCPGetWscaleTest03(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL); DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
FlowShutdown();
if (p->tcph == NULL) { if (p->tcph == NULL) {
printf("tcp packet decode failed: "); printf("tcp packet decode failed: ");
@ -423,6 +427,8 @@ static int TCPGetWscaleTest03(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }
@ -456,7 +462,6 @@ static int TCPGetSackTest01(void)
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL); DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
FlowShutdown();
if (p->tcph == NULL) { if (p->tcph == NULL) {
printf("tcp packet decode failed: "); printf("tcp packet decode failed: ");
@ -487,6 +492,8 @@ static int TCPGetSackTest01(void)
retval = 1; retval = 1;
end: end:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return retval; return retval;
} }

@ -40,6 +40,10 @@
#include "util-unittest.h" #include "util-unittest.h"
#include "util-debug.h" #include "util-debug.h"
#include "pkt-var.h"
#include "util-profiling.h"
#include "host.h"
/** /**
* \internal * \internal
* \brief this function is used to decode IEEE802.1q packets * \brief this function is used to decode IEEE802.1q packets
@ -215,25 +219,29 @@ static int DecodeVLANtest03 (void) {
DecodeVLAN(&tv, &dtv, p, raw_vlan, sizeof(raw_vlan), NULL); DecodeVLAN(&tv, &dtv, p, raw_vlan, sizeof(raw_vlan), NULL);
FlowShutdown();
if(p->vlanh == NULL) { if(p->vlanh == NULL) {
SCFree(p); goto error;
return 0;
} }
if(ENGINE_ISSET_EVENT(p,VLAN_HEADER_TOO_SMALL)) { if(ENGINE_ISSET_EVENT(p,VLAN_HEADER_TOO_SMALL)) {
SCFree(p); goto error;
return 0;
} }
if(ENGINE_ISSET_EVENT(p,VLAN_UNKNOWN_TYPE)) { if(ENGINE_ISSET_EVENT(p,VLAN_UNKNOWN_TYPE)) {
SCFree(p); goto error;
return 0;
} }
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return 1; return 1;
error:
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p);
return 0;
} }
#endif /* UNITTESTS */ #endif /* UNITTESTS */

@ -44,6 +44,9 @@
#include "util-spm-bm.h" #include "util-spm-bm.h"
#include "threads.h" #include "threads.h"
#include "util-unittest-helper.h" #include "util-unittest-helper.h"
#include "pkt-var.h"
#include "host.h"
#include "util-profiling.h"
int DetectContentMatch (ThreadVars *, DetectEngineThreadCtx *, Packet *, Signature *, SigMatch *); int DetectContentMatch (ThreadVars *, DetectEngineThreadCtx *, Packet *, Signature *, SigMatch *);
int DetectContentSetup(DetectEngineCtx *, Signature *, char *); int DetectContentSetup(DetectEngineCtx *, Signature *, char *);
@ -682,6 +685,7 @@ end:
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
} }
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);

@ -35,6 +35,10 @@
#include "util-unittest.h" #include "util-unittest.h"
#include "util-debug.h" #include "util-debug.h"
#include "pkt-var.h"
#include "host.h"
#include "util-profiling.h"
/* prototypes for the "ipv4-csum" rule keyword */ /* prototypes for the "ipv4-csum" rule keyword */
int DetectIPV4CsumMatch(ThreadVars *, DetectEngineThreadCtx *, Packet *, int DetectIPV4CsumMatch(ThreadVars *, DetectEngineThreadCtx *, Packet *,
Signature *, SigMatch *); Signature *, SigMatch *);
@ -1559,6 +1563,7 @@ int DetectCsumICMPV6Test01(void)
} }
StreamTcpFreeConfig(TRUE); StreamTcpFreeConfig(TRUE);
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);

@ -37,6 +37,10 @@
#include "util-debug.h" #include "util-debug.h"
#include "util-byte.h" #include "util-byte.h"
#include "pkt-var.h"
#include "host.h"
#include "util-profiling.h"
/** /**
* dsize:[<>]<0-65535>[<><0-65535>]; * dsize:[<>]<0-65535>[<><0-65535>];
*/ */
@ -790,6 +794,7 @@ cleanup:
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
end: end:
SCFree(p); SCFree(p);

@ -48,6 +48,10 @@
#include "util-debug.h" #include "util-debug.h"
#include "util-error.h" #include "util-error.h"
#include "pkt-var.h"
#include "host.h"
#include "util-profiling.h"
static int DetectPortCutNot(DetectPort *, DetectPort **); static int DetectPortCutNot(DetectPort *, DetectPort **);
static int DetectPortCut(DetectEngineCtx *, DetectPort *, DetectPort *, static int DetectPortCut(DetectEngineCtx *, DetectPort *, DetectPort *,
DetectPort **); DetectPort **);
@ -2444,6 +2448,7 @@ int PortTestMatchReal(uint8_t *raw_eth_pkt, uint16_t pktsize, char *sig,
FlowInitConfig(FLOW_QUIET); FlowInitConfig(FLOW_QUIET);
Packet *p = UTHBuildPacketFromEth(raw_eth_pkt, pktsize); Packet *p = UTHBuildPacketFromEth(raw_eth_pkt, pktsize);
result = UTHPacketMatchSig(p, sig); result = UTHPacketMatchSig(p, sig);
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
return result; return result;
} }

@ -40,6 +40,10 @@
#include "detect-engine.h" #include "detect-engine.h"
#include "detect-engine-mpm.h" #include "detect-engine-mpm.h"
#include "pkt-var.h"
#include "host.h"
#include "util-profiling.h"
/* name modifiers value */ /* name modifiers value */
#define PARSE_REGEX "^\\s*([a-zA-Z][\\w\\d_.]+)\\s*,\\s*([+=-]{1}|==|!=|<|<=|>|>=|isset|notset)\\s*,?\\s*([a-zA-Z][\\w\\d]+|[\\d]{1,10})?\\s*$" #define PARSE_REGEX "^\\s*([a-zA-Z][\\w\\d_.]+)\\s*,\\s*([+=-]{1}|==|!=|<|<=|>|>=|isset|notset)\\s*,?\\s*([a-zA-Z][\\w\\d]+|[\\d]{1,10})?\\s*$"
/* Varnames must begin with a letter */ /* Varnames must begin with a letter */
@ -1400,6 +1404,7 @@ int DetectFlowintTestPacket01Real()
break; break;
} }
SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt); SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt);
PACKET_RECYCLE(p);
} }
SigGroupCleanup(de_ctx); SigGroupCleanup(de_ctx);
@ -1422,6 +1427,7 @@ end:
if (de_ctx) if (de_ctx)
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);
return result; return result;
@ -1736,6 +1742,7 @@ int DetectFlowintTestPacket02Real()
break; break;
} }
SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt); SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt);
PACKET_RECYCLE(p);
} }
SigGroupCleanup(de_ctx); SigGroupCleanup(de_ctx);
@ -2065,6 +2072,7 @@ int DetectFlowintTestPacket03Real()
break; break;
} }
SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt); SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt);
PACKET_RECYCLE(p);
} }
SigGroupCleanup(de_ctx); SigGroupCleanup(de_ctx);

@ -38,6 +38,10 @@
#include "util-unittest.h" #include "util-unittest.h"
#include "util-debug.h" #include "util-debug.h"
#include "pkt-var.h"
#include "host.h"
#include "util-profiling.h"
/** /**
* Regex * Regex
* fragbits: [!+*](MDR) * fragbits: [!+*](MDR)
@ -524,7 +528,6 @@ static int FragBitsTestParse04 (void) {
DecodeEthernet(&tv, &dtv, p, raw_eth, sizeof(raw_eth), NULL); DecodeEthernet(&tv, &dtv, p, raw_eth, sizeof(raw_eth), NULL);
FlowShutdown();
de = DetectFragBitsParse("!D"); de = DetectFragBitsParse("!D");
@ -543,6 +546,8 @@ static int FragBitsTestParse04 (void) {
if(ret) { if(ret) {
if (de) SCFree(de); if (de) SCFree(de);
if (sm) SCFree(sm); if (sm) SCFree(sm);
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return 1; return 1;
} }
@ -550,6 +555,8 @@ static int FragBitsTestParse04 (void) {
error: error:
if (de) SCFree(de); if (de) SCFree(de);
if (sm) SCFree(sm); if (sm) SCFree(sm);
PACKET_RECYCLE(p);
FlowShutdown();
SCFree(p); SCFree(p);
return 0; return 0;
} }

@ -39,6 +39,11 @@
#include "detect-ipproto.h" #include "detect-ipproto.h"
#include "detect-flow.h" #include "detect-flow.h"
#include "pkt-var.h"
#include "host.h"
#include "util-profiling.h"
#include "decode.h"
#include "flow.h" #include "flow.h"
#include "util-rule-vars.h" #include "util-rule-vars.h"
@ -2671,8 +2676,10 @@ int SigTestBidirec03 (void) {
result = UTHCheckPacketMatchResults(p, sids, results, 1); result = UTHCheckPacketMatchResults(p, sids, results, 1);
end: end:
if (p != NULL) if (p != NULL) {
PACKET_RECYCLE(p);
SCFree(p); SCFree(p);
}
if (de_ctx != NULL) { if (de_ctx != NULL) {
SigCleanSignatures(de_ctx); SigCleanSignatures(de_ctx);
SigGroupCleanup(de_ctx); SigGroupCleanup(de_ctx);
@ -2815,6 +2822,9 @@ int SigTestBidirec04 (void) {
result = 1; result = 1;
} }
if (p != NULL) {
PACKET_RECYCLE(p);
}
FlowShutdown(); FlowShutdown();
//PatternMatchDestroy(mpm_ctx); //PatternMatchDestroy(mpm_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);

@ -55,6 +55,10 @@ extern int run_mode;
#include "util-debug.h" #include "util-debug.h"
#include "pkt-var.h"
#include "host.h"
#include "util-profiling.h"
static int DetectReplaceSetup (DetectEngineCtx *, Signature *, char *); static int DetectReplaceSetup (DetectEngineCtx *, Signature *, char *);
void DetectReplaceRegisterTests(void); void DetectReplaceRegisterTests(void);
@ -285,6 +289,7 @@ end:
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
} }
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);

@ -8710,6 +8710,7 @@ int SigTest36ContentAndIsdataatKeywords01Real (int mpm_type) {
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
//PatternMatchDestroy(mpm_ctx); //PatternMatchDestroy(mpm_ctx);
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);
@ -8730,6 +8731,9 @@ end:
if(de_ctx) if(de_ctx)
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
if (p != NULL)
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);
@ -8842,6 +8846,8 @@ int SigTest37ContentAndIsdataatKeywords02Real (int mpm_type) {
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx); DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);
@ -8860,6 +8866,9 @@ end:
if(de_ctx) if(de_ctx)
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
if (p != NULL)
PACKET_RECYCLE(p);
FlowShutdown(); FlowShutdown();
SCFree(p); SCFree(p);
@ -10497,15 +10506,23 @@ end:
if (de_ctx != NULL) if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx); DetectEngineCtxFree(de_ctx);
FlowShutdown(); if (p1 != NULL) {
if (p1 != NULL) PACKET_RECYCLE(p1);
SCFree(p1); SCFree(p1);
if (p2 != NULL) }
if (p2 != NULL) {
PACKET_RECYCLE(p2);
SCFree(p2); SCFree(p2);
if (p3 != NULL) }
if (p3 != NULL) {
PACKET_RECYCLE(p3);
SCFree(p3); SCFree(p3);
if (p4 != NULL) }
if (p4 != NULL) {
PACKET_RECYCLE(p4);
SCFree(p4); SCFree(p4);
}
FlowShutdown();
return result; return result;
} }

Loading…
Cancel
Save