]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Fix several compile and runtime warnings found by clang 3.2 with the -fsanitize=addre...
authorVictor Julien <victor@inliniac.net>
Fri, 20 Sep 2013 11:06:55 +0000 (13:06 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 20 Sep 2013 11:06:55 +0000 (13:06 +0200)
src/counters.c
src/defrag.c
src/detect-csum.c
src/detect-engine-hhd.c
src/detect-flow.c
src/detect.c
src/flow-storage.c
src/util-mpm-b3g.c

index d023594935850f457607565e265bb421d71718db..f574f742a9d6c9da702444721f87498c2fe14992 100644 (file)
@@ -2326,11 +2326,11 @@ static int SCPerfTestAverageQual12()
     result &= (0 == pca->head[1].wrapped_syncs);
     result &= (3.5 == *((double *)tv.sc_perf_pctx.head->value->cvalue) );
 
-    SCPerfCounterAddUI64(id2, pca, 1.635);
-    SCPerfCounterAddUI64(id2, pca, 2.12);
-    SCPerfCounterAddUI64(id2, pca, 3.74);
-    SCPerfCounterAddUI64(id2, pca, 4.23);
-    SCPerfCounterAddUI64(id2, pca, 5.76);
+    SCPerfCounterAddUI64(id2, pca, (uint64_t)1.635);
+    SCPerfCounterAddUI64(id2, pca, (uint64_t)2.12);
+    SCPerfCounterAddUI64(id2, pca, (uint64_t)3.74);
+    SCPerfCounterAddUI64(id2, pca, (uint64_t)4.23);
+    SCPerfCounterAddUI64(id2, pca, (uint64_t)5.76);
     SCPerfCounterAddDouble(id2, pca, 6.99999);
 
     SCPerfUpdateCounterArray(pca, &tv.sc_perf_pctx, 0);
index f230a09cc354ee57d5b9f9e16d3aae7fb6217b34..9cc25a8c05222cfc58df592b5ec495adae49bb43 100644 (file)
@@ -937,7 +937,7 @@ BuildTestPacket(uint16_t id, uint16_t off, int mf, const char content,
     ip4h.s_ip_dst.s_addr = 0x02020202; /* 2.2.2.2 */
 
     /* copy content_len crap, we need full length */
-    PacketCopyData(p, (uint8_t *)&ip4h, sizeof(ip4h) + content_len);
+    PacketCopyData(p, (uint8_t *)&ip4h, sizeof(ip4h));
     p->ip4h = (IPV4Hdr *)GET_PKT_DATA(p);
     SET_IPV4_SRC_ADDR(p, &p->src);
     SET_IPV4_DST_ADDR(p, &p->dst);
@@ -1007,7 +1007,7 @@ IPV6BuildTestPacket(uint32_t id, uint16_t off, int mf, const char content,
     ip6h.s_ip6_dst[3] = 0x02020202;
 
     /* copy content_len crap, we need full length */
-    PacketCopyData(p, (uint8_t *)&ip6h, sizeof(IPV6Hdr) + sizeof(IPV6FragHdr) + content_len);
+    PacketCopyData(p, (uint8_t *)&ip6h, sizeof(IPV6Hdr));
 
     p->ip6h = (IPV6Hdr *)GET_PKT_DATA(p);
     IPV6_SET_RAW_VER(p->ip6h, 6);
index c5606f4b5aa3fdc6a6c45052baabe07edc23ec96..c45219dff8f2446c2b12a05a77861ba3ade8f547 100644 (file)
@@ -1488,6 +1488,10 @@ int DetectCsumICMPV6Test01(void)
 {
     int result = 0;
     DetectEngineCtx *de_ctx = NULL;
+    Signature *s = NULL;
+    ThreadVars tv;
+    DetectEngineThreadCtx *det_ctx = NULL;
+    DecodeThreadVars dtv;
 
     Packet *p = PacketGetFromAlloc();
     if (p == NULL) {
@@ -1514,10 +1518,6 @@ int DetectCsumICMPV6Test01(void)
 
     PacketCopyData(p, pkt, sizeof(pkt));
 
-    Signature *s = NULL;
-    ThreadVars tv;
-    DetectEngineThreadCtx *det_ctx = NULL;
-    DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(tv));
     memset(&dtv, 0, sizeof(dtv));
index 777874d6da59a3fd8476eaf7e410867fdeb61484..973854f8c8d5d901119f50b0134251f2edf2fd6a 100644 (file)
@@ -81,7 +81,6 @@ static inline int HHDCreateSpace(DetectEngineThreadCtx *det_ctx, uint16_t size)
     return 0;
 }
 
-
 static uint8_t *DetectEngineHHDGetBufferForTX(htp_tx_t *tx, uint64_t tx_id,
                                               DetectEngineCtx *de_ctx,
                                               DetectEngineThreadCtx *det_ctx,
@@ -181,7 +180,7 @@ static uint8_t *DetectEngineHHDGetBufferForTX(htp_tx_t *tx, uint64_t tx_id,
     det_ctx->hhd_buffers[index] = headers_buffer;
     det_ctx->hhd_buffers_len[index] = headers_buffer_len;
 
-    *buffer_len = headers_buffer_len;
+    *buffer_len = (uint32_t)headers_buffer_len;
  end:
     return headers_buffer;
 }
index fa7d3242faba0965f56fd35157f624aa0752036b..fa784a777cdca18e1d4368e362db5cd756bdac78 100644 (file)
@@ -998,9 +998,13 @@ int DetectFlowTestParse21 (void) {
 static int DetectFlowSigTest01(void)
 {
     int result = 0;
-
+    ThreadVars th_v;
+    DecodeThreadVars dtv;
+    DetectEngineCtx *de_ctx = NULL;
+    DetectEngineThreadCtx *det_ctx = NULL;
     uint8_t *buf = (uint8_t *)"supernovaduper";
     uint16_t buflen = strlen((char *)buf);
+
     Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
     if (p->flow != NULL) {
         printf("packet has flow set\n");
@@ -1010,14 +1014,10 @@ static int DetectFlowSigTest01(void)
     char *sig1 = "alert tcp any any -> any any (msg:\"dummy\"; "
         "content:\"nova\"; flow:no_stream; sid:1;)";
 
-    ThreadVars th_v;
-    DecodeThreadVars dtv;
-    DetectEngineThreadCtx *det_ctx = NULL;
-
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&th_v, 0, sizeof(th_v));
 
-    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    de_ctx = DetectEngineCtxInit();
     if (de_ctx == NULL) {
         printf("de_ctx == NULL: ");
         goto end;
index 8612e52cd5310ea14e8aad82d7960db7020a6c3d..143e5eae9eb7f9470bc5f5d11d491089863bc594 100644 (file)
@@ -6749,7 +6749,7 @@ int SigTest26TCPV4Keyword(void)
     }
 
     ThreadVars th_v;
-    DetectEngineThreadCtx *det_ctx;
+    DetectEngineThreadCtx *det_ctx = NULL;
     int result = 0;
 
     memset(&th_v, 0, sizeof(ThreadVars));
@@ -6863,7 +6863,7 @@ static int SigTest27NegativeTCPV4Keyword(void)
         return 0;
     }
     ThreadVars th_v;
-    DetectEngineThreadCtx *det_ctx;
+    DetectEngineThreadCtx *det_ctx = NULL;
     int result = 0;
 
     memset(&th_v, 0, sizeof(ThreadVars));
@@ -6991,7 +6991,7 @@ int SigTest28TCPV6Keyword(void)
         return 0;
     }
     ThreadVars th_v;
-    DetectEngineThreadCtx *det_ctx;
+    DetectEngineThreadCtx *det_ctx = NULL;
     int result = 0;
 
     memset(&th_v, 0, sizeof(ThreadVars));
index 4a1b154710ee3ce6c7517e0358f5107bed50ce82..d1a3a9bc5f0449e0b2dfcd06941228408cdbf66e 100644 (file)
@@ -72,6 +72,8 @@ static void StorageTestFree(void *x) {
 }
 
 static int FlowStorageTest01(void) {
+    Flow *f = NULL;
+
     StorageInit();
 
     int id1 = FlowStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
@@ -88,7 +90,8 @@ static int FlowStorageTest01(void) {
         goto error;
 
     FlowInitConfig(FLOW_QUIET);
-    Flow *f = FlowAlloc();
+
+    f = FlowAlloc();
     if (f == NULL) {
         goto error;
     }
@@ -138,14 +141,18 @@ static int FlowStorageTest01(void) {
     StorageCleanup();
     return 1;
 error:
-    FlowClearMemory(f, 0);
-    FlowFree(f);
+    if (f != NULL) {
+        FlowClearMemory(f, 0);
+        FlowFree(f);
+    }
     FlowShutdown();
     StorageCleanup();
     return 0;
 }
 
 static int FlowStorageTest02(void) {
+    Flow *f = NULL;
+
     StorageInit();
 
     int id1 = FlowStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
@@ -156,7 +163,7 @@ static int FlowStorageTest02(void) {
         goto error;
 
     FlowInitConfig(FLOW_QUIET);
-    Flow *f = FlowAlloc();
+    f = FlowAlloc();
     if (f == NULL) {
         goto error;
     }
@@ -184,14 +191,18 @@ static int FlowStorageTest02(void) {
     StorageCleanup();
     return 1;
 error:
-    FlowClearMemory(f, 0);
-    FlowFree(f);
+    if (f != NULL) {
+        FlowClearMemory(f, 0);
+        FlowFree(f);
+    }
     FlowShutdown();
     StorageCleanup();
     return 0;
 }
 
 static int FlowStorageTest03(void) {
+    Flow *f = NULL;
+
     StorageInit();
 
     int id1 = FlowStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
@@ -208,7 +219,7 @@ static int FlowStorageTest03(void) {
         goto error;
 
     FlowInitConfig(FLOW_QUIET);
-    Flow *f = FlowAlloc();
+    f = FlowAlloc();
     if (f == NULL) {
         goto error;
     }
@@ -254,8 +265,10 @@ static int FlowStorageTest03(void) {
     StorageCleanup();
     return 1;
 error:
-    FlowClearMemory(f, 0);
-    FlowFree(f);
+    if (f != NULL) {
+        FlowClearMemory(f, 0);
+        FlowFree(f);
+    }
     FlowShutdown();
     StorageCleanup();
     return 0;
index 1434c416ac82e9f8482b9fbcbea1b270d5271a50..62460c13c7d951b651b26e334db70307c2581c5d 100644 (file)
@@ -1602,7 +1602,12 @@ static int B3gTestSearch10 (void) {
     B3gPreparePatterns(&mpm_ctx);
     B3gThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1 /* 1 pattern */);
 
-    uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)"012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679abcdefgh012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679", 208);
+    char *input = "012345679012345679012345679012345679012345679012345679"
+                  "012345679012345679012345679012345679abcdefgh0123456790"
+                  "123456790123456790123456790123456790123456790123456790"
+                  "12345679012345679012345679";
+
+    uint32_t cnt = ctx->Search(&mpm_ctx, &mpm_thread_ctx, NULL, (uint8_t *)input, strlen(input));
 
     if (cnt == 1)
         result = 1;