From: Victor Julien Date: Fri, 20 Sep 2013 11:06:55 +0000 (+0200) Subject: Fix several compile and runtime warnings found by clang 3.2 with the -fsanitize=addre... X-Git-Tag: suricata-2.0beta2~350 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3470b07ea58781feea94deb4503d30868d4b4040;p=thirdparty%2Fsuricata.git Fix several compile and runtime warnings found by clang 3.2 with the -fsanitize=address option. --- diff --git a/src/counters.c b/src/counters.c index d023594935..f574f742a9 100644 --- a/src/counters.c +++ b/src/counters.c @@ -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); diff --git a/src/defrag.c b/src/defrag.c index f230a09cc3..9cc25a8c05 100644 --- a/src/defrag.c +++ b/src/defrag.c @@ -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); diff --git a/src/detect-csum.c b/src/detect-csum.c index c5606f4b5a..c45219dff8 100644 --- a/src/detect-csum.c +++ b/src/detect-csum.c @@ -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)); diff --git a/src/detect-engine-hhd.c b/src/detect-engine-hhd.c index 777874d6da..973854f8c8 100644 --- a/src/detect-engine-hhd.c +++ b/src/detect-engine-hhd.c @@ -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; } diff --git a/src/detect-flow.c b/src/detect-flow.c index fa7d3242fa..fa784a777c 100644 --- a/src/detect-flow.c +++ b/src/detect-flow.c @@ -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; diff --git a/src/detect.c b/src/detect.c index 8612e52cd5..143e5eae9e 100644 --- a/src/detect.c +++ b/src/detect.c @@ -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)); diff --git a/src/flow-storage.c b/src/flow-storage.c index 4a1b154710..d1a3a9bc5f 100644 --- a/src/flow-storage.c +++ b/src/flow-storage.c @@ -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; diff --git a/src/util-mpm-b3g.c b/src/util-mpm-b3g.c index 1434c416ac..62460c13c7 100644 --- a/src/util-mpm-b3g.c +++ b/src/util-mpm-b3g.c @@ -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;