From 4025567a5ae0334e4d312eff8591ff30dccc4d93 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 20 Jun 2011 09:25:21 +0200 Subject: [PATCH] Fix a number of unittests not properly initializing a packet causing issues on some archs. --- src/alert-unified2-alert.c | 17 ++++++++++++++++- src/decode-ipv4.c | 15 ++++++++++++--- src/defrag.c | 7 +++++++ src/stream-tcp.c | 7 +++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c index fed18ab9c0..fc416d937b 100644 --- a/src/alert-unified2-alert.c +++ b/src/alert-unified2-alert.c @@ -30,7 +30,7 @@ #include "detect.h" #include "flow.h" #include "conf.h" - +#include "pkt-var.h" #include "threads.h" #include "threadvars.h" #include "tm-modules.h" @@ -997,6 +997,8 @@ static int Unified2Test01 (void) { p->pkt = (uint8_t *)(p + 1); memset(&s, 0, sizeof(Signature)); + PACKET_INITIALIZE(p); + p->alerts.cnt++; p->alerts.alerts[p->alerts.cnt-1].s = &s; p->alerts.alerts[p->alerts.cnt-1].s->id = 1; @@ -1038,6 +1040,7 @@ static int Unified2Test01 (void) { Unified2AlertDeInitCtx(oc); + PACKET_CLEANUP(p); SCFree(p); return 1; } @@ -1083,6 +1086,8 @@ static int Unified2Test02 (void) { p->pkt = (uint8_t *)(p + 1); memset(&s, 0, sizeof(Signature)); + PACKET_INITIALIZE(p); + p->alerts.cnt++; p->alerts.alerts[p->alerts.cnt-1].s = &s; p->alerts.alerts[p->alerts.cnt-1].s->id = 1; @@ -1124,6 +1129,7 @@ static int Unified2Test02 (void) { Unified2AlertDeInitCtx(oc); + PACKET_CLEANUP(p); SCFree(p); return 1; } @@ -1175,6 +1181,8 @@ static int Unified2Test03 (void) { p->pkt = (uint8_t *)(p + 1); memset(&s, 0, sizeof(Signature)); + PACKET_INITIALIZE(p); + p->alerts.cnt++; p->alerts.alerts[p->alerts.cnt-1].s = &s; p->alerts.alerts[p->alerts.cnt-1].s->id = 1; @@ -1222,6 +1230,7 @@ static int Unified2Test03 (void) { pkt = PacketDequeue(&pq); } + PACKET_CLEANUP(p); SCFree(p); return 1; } @@ -1261,6 +1270,8 @@ static int Unified2Test04 (void) { p->pkt = (uint8_t *)(p + 1); memset(&s, 0, sizeof(Signature)); + PACKET_INITIALIZE(p); + p->alerts.cnt++; p->alerts.alerts[p->alerts.cnt-1].s = &s; p->alerts.alerts[p->alerts.cnt-1].s->id = 1; @@ -1302,6 +1313,7 @@ static int Unified2Test04 (void) { Unified2AlertDeInitCtx(oc); + PACKET_CLEANUP(p); SCFree(p); return 1; } @@ -1345,6 +1357,8 @@ static int Unified2Test05 (void) { p->pkt = (uint8_t *)(p + 1); memset(&s, 0, sizeof(Signature)); + PACKET_INITIALIZE(p); + p->alerts.cnt++; p->alerts.alerts[p->alerts.cnt-1].s = &s; p->alerts.alerts[p->alerts.cnt-1].s->id = 1; @@ -1388,6 +1402,7 @@ static int Unified2Test05 (void) { Unified2AlertDeInitCtx(oc); + PACKET_CLEANUP(p); SCFree(p); return 1; } diff --git a/src/decode-ipv4.c b/src/decode-ipv4.c index 6e756552a7..076b290057 100644 --- a/src/decode-ipv4.c +++ b/src/decode-ipv4.c @@ -1545,6 +1545,7 @@ int DecodeIPV4DefragTest01(void) memset(&pq, 0, sizeof(PacketQueue)); memset(p, 0, sizeof(Packet)); + PACKET_INITIALIZE(p); FlowInitConfig(FLOW_QUIET); p->pkt = pkt1; @@ -1612,10 +1613,12 @@ int DecodeIPV4DefragTest01(void) } } + PACKET_CLEANUP(p); SCFree(tp); - end: +end: FlowShutdown(); + PACKET_CLEANUP(p); SCFree(p); return result; } @@ -1685,6 +1688,7 @@ int DecodeIPV4DefragTest02(void) memset(&pq, 0, sizeof(PacketQueue)); memset(p, 0, sizeof(Packet)); + PACKET_INITIALIZE(p); FlowInitConfig(FLOW_QUIET); p->pkt = pkt1; @@ -1753,10 +1757,12 @@ int DecodeIPV4DefragTest02(void) } } + PACKET_CLEANUP(p); SCFree(tp); - end: +end: FlowShutdown(); + PACKET_CLEANUP(p); SCFree(p); return result; } @@ -1822,6 +1828,7 @@ int DecodeIPV4DefragTest03(void) memset(&pq, 0, sizeof(PacketQueue)); memset(p, 0, sizeof(Packet)); + PACKET_INITIALIZE(p); FlowInitConfig(FLOW_QUIET); p->pkt = pkt; @@ -1915,10 +1922,12 @@ int DecodeIPV4DefragTest03(void) } } + PACKET_CLEANUP(p); SCFree(tp); - end: +end: FlowShutdown(); + PACKET_CLEANUP(p); SCFree(p); return result; } diff --git a/src/defrag.c b/src/defrag.c index 30163b638c..bf94a5a6dd 100644 --- a/src/defrag.c +++ b/src/defrag.c @@ -1273,7 +1273,11 @@ BuildTestPacket(uint16_t id, uint16_t off, int mf, const char content, p = SCCalloc(1, sizeof(*p) + default_packet_size); if (p == NULL) return NULL; + + PACKET_INITIALIZE(p); + p->pkt = ((uint8_t *)p) + sizeof(*p); + gettimeofday(&p->ts, NULL); //p->ip4h = (IPV4Hdr *)GET_PKT_DATA(p); ip4h.ip_verhl = 4 << 4; @@ -1343,6 +1347,9 @@ IPV6BuildTestPacket(uint32_t id, uint16_t off, int mf, const char content, p = SCCalloc(1, sizeof(*p) + default_packet_size); if (p == NULL) return NULL; + + PACKET_INITIALIZE(p); + p->pkt = ((uint8_t *)p) + sizeof(*p); gettimeofday(&p->ts, NULL); diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 7837182b20..cb32171855 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -56,6 +56,8 @@ #include "stream-tcp-util.h" #include "stream.h" +#include "pkt-var.h" + #include "app-layer-parser.h" #include "app-layer-protos.h" @@ -8670,6 +8672,8 @@ static int StreamTcpTest40(void) { memset(&tv, 0, sizeof(ThreadVars)); memset(p, 0, SIZE_OF_PACKET); + PACKET_INITIALIZE(p); + p->pkt = (uint8_t *)(p + 1); SET_PKT_LEN(p, sizeof(raw_vlan)); memcpy(GET_PKT_DATA(p), raw_vlan, sizeof(raw_vlan)); @@ -8702,6 +8706,7 @@ static int StreamTcpTest40(void) { } FlowShutdown(); + PACKET_CLEANUP(p); return 1; } @@ -8735,6 +8740,7 @@ static int StreamTcpTest41(void) { return 1; } + PACKET_INITIALIZE(p); FlowInitConfig(FLOW_QUIET); DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p), NULL); @@ -8764,6 +8770,7 @@ static int StreamTcpTest41(void) { } FlowShutdown(); + PACKET_CLEANUP(p); SCFree(p); return 1;