From: Philippe Antoine Date: Thu, 27 Mar 2025 14:13:13 +0000 (+0100) Subject: detect: fix some -Wshorten-64-to-32 warnings X-Git-Tag: suricata-8.0.0-rc1~346 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=41fcf3b3561ef83670ceacc6324612b60d97eb47;p=thirdparty%2Fsuricata.git detect: fix some -Wshorten-64-to-32 warnings Ticket: #6186 --- diff --git a/src/detect-bsize.c b/src/detect-bsize.c index 3933953cd2..fba8c896e7 100644 --- a/src/detect-bsize.c +++ b/src/detect-bsize.c @@ -41,37 +41,38 @@ /*prototypes*/ static int DetectBsizeSetup (DetectEngineCtx *, Signature *, const char *); static void DetectBsizeFree (DetectEngineCtx *, void *); -static int SigParseGetMaxBsize(const DetectU64Data *bsz); +static int SigParseGetMaxBsize(const DetectU64Data *bsz, uint64_t *bsize); #ifdef UNITTESTS static void DetectBsizeRegisterTests (void); #endif bool DetectBsizeValidateContentCallback(Signature *s, const SignatureInitDataBuffer *b) { - int bsize = -1; + uint64_t bsize; + int retval = -1; const DetectU64Data *bsz; for (const SigMatch *sm = b->head; sm != NULL; sm = sm->next) { if (sm->type == DETECT_BSIZE) { bsz = (const DetectU64Data *)sm->ctx; - bsize = SigParseGetMaxBsize(bsz); + retval = SigParseGetMaxBsize(bsz, &bsize); break; } } - if (bsize == -1) { + if (retval == -1) { return true; } uint64_t needed; - if (bsize >= 0) { + if (retval == 0) { int len, offset; SigParseRequiredContentSize(s, bsize, b->head, &len, &offset); - SCLogDebug("bsize: %d; len: %d; offset: %d [%s]", bsize, len, offset, s->sig_str); + SCLogDebug("bsize: %" PRIu64 "; len: %d; offset: %d [%s]", bsize, len, offset, s->sig_str); needed = len; - if (len > bsize) { + if ((uint64_t)len > bsize) { goto value_error; } - if ((len + offset) > bsize) { + if ((uint64_t)(len + offset) > bsize) { needed += offset; goto value_error; } @@ -159,14 +160,16 @@ int DetectBsizeMatch(const SigMatchCtx *ctx, const uint64_t buffer_size, bool eo return 0; } -static int SigParseGetMaxBsize(const DetectU64Data *bsz) +static int SigParseGetMaxBsize(const DetectU64Data *bsz, uint64_t *bsize) { switch (bsz->mode) { case DETECT_UINT_LT: case DETECT_UINT_EQ: - return bsz->arg1; + *bsize = bsz->arg1; + SCReturnInt(0); case DETECT_UINT_RA: - return bsz->arg2; + *bsize = bsz->arg2; + SCReturnInt(0); case DETECT_UINT_GT: default: SCReturnInt(-2); diff --git a/src/detect-byte-extract.c b/src/detect-byte-extract.c index dc83020d2e..40e6911c5e 100644 --- a/src/detect-byte-extract.c +++ b/src/detect-byte-extract.c @@ -159,7 +159,7 @@ int DetectByteExtractDoMatch(DetectEngineThreadCtx *det_ctx, const SigMatchData ptr += extbytes; - det_ctx->buffer_offset = ptr - payload; + det_ctx->buffer_offset = (uint32_t)(ptr - payload); *value = val; SCLogDebug("extracted value is %"PRIu64, val); diff --git a/src/detect-bytejump.c b/src/detect-bytejump.c index 668333fd0d..7e9947a041 100644 --- a/src/detect-bytejump.c +++ b/src/detect-bytejump.c @@ -254,7 +254,7 @@ bool DetectBytejumpDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s, /* Adjust the detection context to the jump location. */ DEBUG_VALIDATE_BUG_ON(jumpptr < payload); - det_ctx->buffer_offset = jumpptr - payload; + det_ctx->buffer_offset = (uint32_t)(jumpptr - payload); SCReturnBool(true); } diff --git a/src/detect-bytemath.c b/src/detect-bytemath.c index 2a651567d9..4e38fd1a04 100644 --- a/src/detect-bytemath.c +++ b/src/detect-bytemath.c @@ -192,7 +192,7 @@ int DetectByteMathDoMatch(DetectEngineThreadCtx *det_ctx, const DetectByteMathDa break; } - det_ctx->buffer_offset = ptr - payload; + det_ctx->buffer_offset = (uint32_t)(ptr - payload); if (data->flags & DETECT_BYTEMATH_FLAG_BITMASK) { val &= data->bitmask_val; diff --git a/src/detect-bytetest.c b/src/detect-bytetest.c index 051523306e..a91a7929aa 100644 --- a/src/detect-bytetest.c +++ b/src/detect-bytetest.c @@ -402,7 +402,7 @@ static DetectBytetestData *DetectBytetestParse( data->neg_op = true; op_ptr = &args[1][1]; while (isspace((char)*op_ptr) || (*op_ptr == ',')) op_ptr++; - op_offset = op_ptr - &args[1][0]; + op_offset = (uint32_t)(op_ptr - &args[1][0]); } else { data->neg_op = false; } diff --git a/src/detect-content.c b/src/detect-content.c index 3c6cab3347..3f7d78f052 100644 --- a/src/detect-content.c +++ b/src/detect-content.c @@ -408,7 +408,7 @@ void DetectContentFree(DetectEngineCtx *de_ctx, void *ptr) * - Negated content values are checked but not accumulated for the required size. */ void SigParseRequiredContentSize( - const Signature *s, const int max_size, const SigMatch *sm, int *len, int *offset) + const Signature *s, const uint64_t max_size, const SigMatch *sm, int *len, int *offset) { int max_offset = 0, total_len = 0; bool first = true; @@ -430,7 +430,7 @@ void SigParseRequiredContentSize( if (cd->flags & DETECT_CONTENT_NEGATED) { /* Check if distance/within cause max to be exceeded */ int check = total_len + cd->distance + cd->within; - if (max_size < check) { + if (max_size < (uint64_t)check) { *len = check; return; } @@ -459,12 +459,11 @@ bool DetectContentPMATCHValidateCallback(const Signature *s) return true; } - int max_right_edge_i = SigParseGetMaxDsize(s); - if (max_right_edge_i < 0) { + uint16_t max_right_edge_i; + if (SigParseGetMaxDsize(s, &max_right_edge_i) < 0) { return true; } - - uint32_t max_right_edge = (uint32_t)max_right_edge_i; + uint32_t max_right_edge = max_right_edge_i; int min_dsize_required = SigParseMaxRequiredDsize(s); if (min_dsize_required >= 0) { diff --git a/src/detect-content.h b/src/detect-content.h index 0968e4d6ea..95bb07c809 100644 --- a/src/detect-content.h +++ b/src/detect-content.h @@ -131,7 +131,7 @@ void DetectContentPropagateLimits(Signature *s); void DetectContentPatternPrettyPrint(const DetectContentData *cd, char *str, size_t str_len); void SigParseRequiredContentSize( - const Signature *s, const int max, const SigMatch *sm, int *len, int *offset); + const Signature *s, const uint64_t max, const SigMatch *sm, int *len, int *offset); int DetectContentConvertToNocase(DetectEngineCtx *de_ctx, DetectContentData *cd); #endif /* SURICATA_DETECT_CONTENT_H */ diff --git a/src/detect-dsize.c b/src/detect-dsize.c index 1aae09e896..1462ccc05b 100644 --- a/src/detect-dsize.c +++ b/src/detect-dsize.c @@ -209,7 +209,7 @@ static bool PrefilterDsizeIsPrefilterable(const Signature *s) * \param s signature to get dsize value from * \retval depth or negative value */ -int SigParseGetMaxDsize(const Signature *s) +int SigParseGetMaxDsize(const Signature *s, uint16_t *dsize) { if (s->flags & SIG_FLAG_DSIZE && s->init_data->dsize_sm != NULL) { const DetectU16Data *dd = (const DetectU16Data *)s->init_data->dsize_sm->ctx; @@ -218,9 +218,11 @@ int SigParseGetMaxDsize(const Signature *s) case DETECT_UINT_LT: case DETECT_UINT_EQ: case DETECT_UINT_NE: - return dd->arg1; + *dsize = dd->arg1; + SCReturnInt(0); case DETECT_UINT_RA: - return dd->arg2; + *dsize = dd->arg2; + SCReturnInt(0); case DETECT_UINT_GT: default: SCReturnInt(-2); @@ -294,8 +296,8 @@ int SigParseMaxRequiredDsize(const Signature *s) SCReturnInt(-1); } - const int dsize = SigParseGetMaxDsize(s); - if (dsize < 0) { + uint16_t dsize; + if (SigParseGetMaxDsize(s, &dsize) < 0) { /* nothing to do */ SCReturnInt(-1); } @@ -329,8 +331,8 @@ void SigParseApplyDsizeToContent(Signature *s) if (s->flags & SIG_FLAG_DSIZE) { SigParseSetDsizePair(s); - int dsize = SigParseGetMaxDsize(s); - if (dsize < 0) { + uint16_t dsize; + if (SigParseGetMaxDsize(s, &dsize) < 0) { /* nothing to do */ return; } diff --git a/src/detect-dsize.h b/src/detect-dsize.h index 0d4b8beb3f..ed7f9fccb2 100644 --- a/src/detect-dsize.h +++ b/src/detect-dsize.h @@ -30,7 +30,7 @@ void DetectDsizeRegister (void); int SigParseMaxRequiredDsize(const Signature *s); -int SigParseGetMaxDsize(const Signature *s); +int SigParseGetMaxDsize(const Signature *s, uint16_t *dsize); void SigParseSetDsizePair(Signature *s); void SigParseApplyDsizeToContent(Signature *s); diff --git a/src/detect-engine-analyzer.c b/src/detect-engine-analyzer.c index 35150a57bc..ecc25a903c 100644 --- a/src/detect-engine-analyzer.c +++ b/src/detect-engine-analyzer.c @@ -482,7 +482,7 @@ void SetupEngineAnalysis(DetectEngineCtx *de_ctx, bool *fp_analysis, bool *rule_ } ea->file_prefix = NULL; - int cfg_prefix_len = strlen(de_ctx->config_prefix); + size_t cfg_prefix_len = strlen(de_ctx->config_prefix); if (cfg_prefix_len > 0) { /* length of prefix + NULL + "." */ ea->file_prefix = SCCalloc(1, cfg_prefix_len + 1 + 1); diff --git a/src/detect-engine-loader.c b/src/detect-engine-loader.c index f58433bdf1..c51f17ce80 100644 --- a/src/detect-engine-loader.c +++ b/src/detect-engine-loader.c @@ -136,7 +136,7 @@ static int DetectLoadSigFile(DetectEngineCtx *de_ctx, const char *sig_file, int return -1; } - while(fgets(line + offset, (int)sizeof(line) - offset, fp) != NULL) { + while (fgets(line + offset, (int)(sizeof(line) - offset), fp) != NULL) { lineno++; size_t len = strlen(line); diff --git a/src/detect-engine-prefilter-common.c b/src/detect-engine-prefilter-common.c index 6c5ff62548..718d31f822 100644 --- a/src/detect-engine-prefilter-common.c +++ b/src/detect-engine-prefilter-common.c @@ -33,7 +33,7 @@ static uint32_t PrefilterPacketHeaderHashFunc(HashListTable *ht, void *data, uin PrefilterPacketHeaderCtx *ctx = data; uint64_t hash = ctx->v1.u64[0] + ctx->v1.u64[1] + ctx->type + ctx->value; hash %= ht->array_size; - return hash; + return (uint32_t)hash; } static char PrefilterPacketHeaderCompareFunc(void *data1, uint16_t len1, diff --git a/src/detect-engine-prefilter.c b/src/detect-engine-prefilter.c index 4062280cba..a2658bf4db 100644 --- a/src/detect-engine-prefilter.c +++ b/src/detect-engine-prefilter.c @@ -85,8 +85,8 @@ static inline void QuickSortSigIntId(SigIntId *sids, uint32_t n) r--; } } - QuickSortSigIntId(sids, r - sids + 1); - QuickSortSigIntId(l, sids + n - l); + QuickSortSigIntId(sids, (uint32_t)(r - sids) + 1); + QuickSortSigIntId(l, (uint32_t)(sids + n - l)); } /** @@ -1394,7 +1394,7 @@ static uint32_t PrefilterStoreHashFunc(HashListTable *ht, void *data, uint16_t d { PrefilterStore *ctx = data; - uint32_t hash = strlen(ctx->name); + uint32_t hash = (uint32_t)strlen(ctx->name); for (size_t u = 0; u < strlen(ctx->name); u++) { hash += ctx->name[u]; diff --git a/src/detect-engine-register.c b/src/detect-engine-register.c index 9038c5fdff..16e1f3fbe6 100644 --- a/src/detect-engine-register.c +++ b/src/detect-engine-register.c @@ -342,7 +342,7 @@ static void PrintFeatureList(const SigTableElmt *e, char sep) } } -static void SigMultilinePrint(int i, const char *prefix) +static void SigMultilinePrint(size_t i, const char *prefix) { if (sigmatch_table[i].desc) { printf("%sDescription: %s\n", prefix, sigmatch_table[i].desc); diff --git a/src/detect-flow-age.c b/src/detect-flow-age.c index 04854831d6..665b081a3b 100644 --- a/src/detect-flow-age.c +++ b/src/detect-flow-age.c @@ -29,10 +29,13 @@ static int DetectFlowAgeMatch( if (p->flow == NULL) { return 0; } - uint32_t age = SCTIME_SECS(p->flow->lastts) - SCTIME_SECS(p->flow->startts); + uint64_t age = SCTIME_SECS(p->flow->lastts) - SCTIME_SECS(p->flow->startts); + if (age > UINT32_MAX) { + age = UINT32_MAX; + } const DetectU32Data *du32 = (const DetectU32Data *)ctx; - return DetectU32Match(age, du32); + return DetectU32Match((uint32_t)age, du32); } static void DetectFlowAgeFree(DetectEngineCtx *de_ctx, void *ptr) diff --git a/src/detect-http-cookie.c b/src/detect-http-cookie.c index 2e614af66f..05c223897f 100644 --- a/src/detect-http-cookie.c +++ b/src/detect-http-cookie.c @@ -188,7 +188,7 @@ static InspectionBuffer *GetRequestData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = htp_header_value_len(h); + const uint32_t data_len = (uint32_t)htp_header_value_len(h); const uint8_t *data = htp_header_value_ptr(h); InspectionBufferSetupAndApplyTransforms( @@ -215,7 +215,7 @@ static InspectionBuffer *GetResponseData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = htp_header_value_len(h); + const uint32_t data_len = (uint32_t)htp_header_value_len(h); const uint8_t *data = htp_header_value_ptr(h); InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-http-header-common.c b/src/detect-http-header-common.c index 401a50fcf5..00079cc00e 100644 --- a/src/detect-http-header-common.c +++ b/src/detect-http-header-common.c @@ -78,8 +78,7 @@ void HttpHeaderThreadDataFree(void *data) SCFree(hdrnames); } -int HttpHeaderExpandBuffer(HttpHeaderThreadData *td, - HttpHeaderBuffer *buf, uint32_t size) +int HttpHeaderExpandBuffer(HttpHeaderThreadData *td, HttpHeaderBuffer *buf, size_t size) { size_t extra = td->size_step; while ((buf->size + extra) < (size + buf->len)) { diff --git a/src/detect-http-header-common.h b/src/detect-http-header-common.h index 4677407943..698e70934e 100644 --- a/src/detect-http-header-common.h +++ b/src/detect-http-header-common.h @@ -45,7 +45,6 @@ void HttpHeaderThreadDataFree(void *data); HttpHeaderBuffer *HttpHeaderGetBufferSpace(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags, const int keyword_id, HttpHeaderThreadData **ret_hdr_td); -int HttpHeaderExpandBuffer(HttpHeaderThreadData *td, - HttpHeaderBuffer *buf, uint32_t size); +int HttpHeaderExpandBuffer(HttpHeaderThreadData *td, HttpHeaderBuffer *buf, size_t size); #endif /* SURICATA_DETECT_HTTP_HEADER_COMMON_H */ diff --git a/src/detect-http-headers-stub.h b/src/detect-http-headers-stub.h index 6a3828f437..aeae5409c2 100644 --- a/src/detect-http-headers-stub.h +++ b/src/detect-http-headers-stub.h @@ -64,7 +64,7 @@ static InspectionBuffer *GetRequestData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = htp_header_value_len(h); + const uint32_t data_len = (uint32_t)htp_header_value_len(h); const uint8_t *data = htp_header_value_ptr(h); InspectionBufferSetupAndApplyTransforms( @@ -118,7 +118,7 @@ static InspectionBuffer *GetResponseData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = htp_header_value_len(h); + const uint32_t data_len = (uint32_t)htp_header_value_len(h); const uint8_t *data = htp_header_value_ptr(h); InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-http-host.c b/src/detect-http-host.c index dcc69b6d6f..a26db438da 100644 --- a/src/detect-http-host.c +++ b/src/detect-http-host.c @@ -251,7 +251,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, if (htp_tx_request_hostname(tx) == NULL) return NULL; - const uint32_t data_len = bstr_len(htp_tx_request_hostname(tx)); + const uint32_t data_len = (uint32_t)bstr_len(htp_tx_request_hostname(tx)); const uint8_t *data = bstr_ptr(htp_tx_request_hostname(tx)); InspectionBufferSetupAndApplyTransforms( @@ -358,10 +358,10 @@ static InspectionBuffer *GetRawData(DetectEngineThreadCtx *det_ctx, return NULL; data = htp_header_value_ptr(h); - data_len = htp_header_value_len(h); + data_len = (uint32_t)htp_header_value_len(h); } else { data = (const uint8_t *)bstr_ptr(htp_uri_hostname(htp_tx_parsed_uri(tx))); - data_len = bstr_len(htp_uri_hostname(htp_tx_parsed_uri(tx))); + data_len = (uint32_t)bstr_len(htp_uri_hostname(htp_tx_parsed_uri(tx))); } InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-http-method.c b/src/detect-http-method.c index 95dba72f48..1b0e191182 100644 --- a/src/detect-http-method.c +++ b/src/detect-http-method.c @@ -210,7 +210,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, if (htp_tx_request_method(tx) == NULL) return NULL; - const uint32_t data_len = bstr_len(htp_tx_request_method(tx)); + const uint32_t data_len = (uint32_t)bstr_len(htp_tx_request_method(tx)); const uint8_t *data = bstr_ptr(htp_tx_request_method(tx)); InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-http-protocol.c b/src/detect-http-protocol.c index 3c298f5ee1..3c2198c117 100644 --- a/src/detect-http-protocol.c +++ b/src/detect-http-protocol.c @@ -101,7 +101,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - uint32_t data_len = bstr_size(str); + uint32_t data_len = (uint32_t)bstr_size(str); uint8_t *data = bstr_ptr(str); if (data == NULL || data_len == 0) { SCLogDebug("HTTP protocol not present"); diff --git a/src/detect-http-request-line.c b/src/detect-http-request-line.c index 0226c87d9d..597812a4b9 100644 --- a/src/detect-http-request-line.c +++ b/src/detect-http-request-line.c @@ -162,7 +162,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, if (unlikely(htp_tx_request_line(tx) == NULL)) { return NULL; } - const uint32_t data_len = bstr_len(htp_tx_request_line(tx)); + const uint32_t data_len = (uint32_t)bstr_len(htp_tx_request_line(tx)); const uint8_t *data = bstr_ptr(htp_tx_request_line(tx)); InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-http-response-line.c b/src/detect-http-response-line.c index 12b7ec1d72..670a1a421a 100644 --- a/src/detect-http-response-line.c +++ b/src/detect-http-response-line.c @@ -161,7 +161,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, if (unlikely(htp_tx_response_line(tx) == NULL)) { return NULL; } - const uint32_t data_len = bstr_len(htp_tx_response_line(tx)); + const uint32_t data_len = (uint32_t)bstr_len(htp_tx_response_line(tx)); const uint8_t *data = bstr_ptr(htp_tx_response_line(tx)); InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-http-stat-code.c b/src/detect-http-stat-code.c index 4c8d58ff24..60506cbf38 100644 --- a/src/detect-http-stat-code.c +++ b/src/detect-http-stat-code.c @@ -167,7 +167,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, if (htp_tx_response_status(tx) == NULL) return NULL; - const uint32_t data_len = bstr_len(htp_tx_response_status(tx)); + const uint32_t data_len = (uint32_t)bstr_len(htp_tx_response_status(tx)); const uint8_t *data = bstr_ptr(htp_tx_response_status(tx)); InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-http-stat-msg.c b/src/detect-http-stat-msg.c index c96c73c422..c57917b1fc 100644 --- a/src/detect-http-stat-msg.c +++ b/src/detect-http-stat-msg.c @@ -176,7 +176,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, if (htp_tx_response_message(tx) == NULL) return NULL; - const uint32_t data_len = bstr_len(htp_tx_response_message(tx)); + const uint32_t data_len = (uint32_t)bstr_len(htp_tx_response_message(tx)); const uint8_t *data = bstr_ptr(htp_tx_response_message(tx)); InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-http-ua.c b/src/detect-http-ua.c index a527bfa0f8..efe7d36290 100644 --- a/src/detect-http-ua.c +++ b/src/detect-http-ua.c @@ -172,7 +172,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = htp_header_value_len(h); + const uint32_t data_len = (uint32_t)htp_header_value_len(h); const uint8_t *data = htp_header_value_ptr(h); InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-http-uri.c b/src/detect-http-uri.c index 0c8e894130..316a150d35 100644 --- a/src/detect-http-uri.c +++ b/src/detect-http-uri.c @@ -221,7 +221,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, if (request_uri_normalized == NULL) return NULL; - const uint32_t data_len = bstr_len(request_uri_normalized); + const uint32_t data_len = (uint32_t)bstr_len(request_uri_normalized); const uint8_t *data = bstr_ptr(request_uri_normalized); InspectionBufferSetupAndApplyTransforms( @@ -306,7 +306,7 @@ static InspectionBuffer *GetRawData(DetectEngineThreadCtx *det_ctx, if (unlikely(htp_tx_request_uri(tx) == NULL)) { return NULL; } - const uint32_t data_len = bstr_len(htp_tx_request_uri(tx)); + const uint32_t data_len = (uint32_t)bstr_len(htp_tx_request_uri(tx)); const uint8_t *data = bstr_ptr(htp_tx_request_uri(tx)); InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-pcre.c b/src/detect-pcre.c index e46ffc21ad..a4585c703e 100644 --- a/src/detect-pcre.c +++ b/src/detect-pcre.c @@ -113,7 +113,7 @@ void DetectPcreRegister (void) pcre_match_limit = SC_MATCH_LIMIT_DEFAULT; SCLogDebug("Using PCRE match-limit setting of: %i", pcre_match_limit); } else { - pcre_match_limit = val; + pcre_match_limit = (int)val; if (pcre_match_limit != SC_MATCH_LIMIT_DEFAULT) { SCLogInfo("Using PCRE match-limit setting of: %i", pcre_match_limit); } else { @@ -127,7 +127,7 @@ void DetectPcreRegister (void) pcre_match_limit_recursion = SC_MATCH_LIMIT_RECURSION_DEFAULT; SCLogDebug("Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion); } else { - pcre_match_limit_recursion = val; + pcre_match_limit_recursion = (int)val; if (pcre_match_limit_recursion != SC_MATCH_LIMIT_RECURSION_DEFAULT) { SCLogInfo("Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion); } else { @@ -191,7 +191,7 @@ int DetectPcrePayloadMatch(DetectEngineThreadCtx *det_ctx, const Signature *s, int start_offset = 0; if (det_ctx->pcre_match_start_offset != 0) { - start_offset = (payload + det_ctx->pcre_match_start_offset - ptr); + start_offset = (uint32_t)(payload - ptr) + det_ctx->pcre_match_start_offset; } /* run the actual pcre detection */ @@ -288,8 +288,8 @@ int DetectPcrePayloadMatch(DetectEngineThreadCtx *det_ctx, const Signature *s, PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match); /* update offset for pcre RELATIVE */ - det_ctx->buffer_offset = (ptr + ov[1]) - payload; - det_ctx->pcre_match_start_offset = (ptr + ov[0] + 1) - payload; + det_ctx->buffer_offset = (uint32_t)((ptr + ov[1]) - payload); + det_ctx->pcre_match_start_offset = (uint32_t)((ptr + ov[0] + 1) - payload); ret = 1; } @@ -369,13 +369,13 @@ static DetectPcreData *DetectPcreParse (DetectEngineCtx *de_ctx, SCLogDebug("regexstr %s", regexstr); if (fcap && !pcap) - cut_capture = fcap - regexstr; + cut_capture = (int)(fcap - regexstr); else if (pcap && !fcap) - cut_capture = pcap - regexstr; + cut_capture = (int)(pcap - regexstr); else { BUG_ON(pcap == NULL); // added to assist cppcheck BUG_ON(fcap == NULL); - cut_capture = MIN((pcap - regexstr), (fcap - regexstr)); + cut_capture = (int)MIN((pcap - regexstr), (fcap - regexstr)); } SCLogDebug("cut_capture %d", cut_capture); diff --git a/src/detect-priority.c b/src/detect-priority.c index 81ee72966f..facd0e82d3 100644 --- a/src/detect-priority.c +++ b/src/detect-priority.c @@ -84,7 +84,7 @@ static int DetectPrioritySetup (DetectEngineCtx *de_ctx, Signature *s, const cha pcre2_match_data_free(match); char *endptr = NULL; - long prio = strtol(copy_str, &endptr, 10); + int prio = (int)strtol(copy_str, &endptr, 10); if (endptr == NULL || *endptr != '\0') { SCLogError("Saw an invalid character as arg " "to priority keyword"); diff --git a/src/detect-reference.c b/src/detect-reference.c index 89b6292abd..cf7e45ea94 100644 --- a/src/detect-reference.c +++ b/src/detect-reference.c @@ -145,7 +145,7 @@ static DetectReference *DetectReferenceParse(const char *rawstr, DetectEngineCtx goto error; } - int ref_len = strlen(uri); + size_t ref_len = strlen(uri); /* no key, reference -- return an error */ if (strlen(key) == 0 || ref_len == 0) goto error; diff --git a/src/detect-tls-cert-fingerprint.c b/src/detect-tls-cert-fingerprint.c index d8350bf832..ebd43668a7 100644 --- a/src/detect-tls-cert-fingerprint.c +++ b/src/detect-tls-cert-fingerprint.c @@ -150,7 +150,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = strlen(connp->cert0_fingerprint); + const uint32_t data_len = (uint32_t)strlen(connp->cert0_fingerprint); const uint8_t *data = (uint8_t *)connp->cert0_fingerprint; InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-tls-cert-issuer.c b/src/detect-tls-cert-issuer.c index e20a369874..3f47a89a30 100644 --- a/src/detect-tls-cert-issuer.c +++ b/src/detect-tls-cert-issuer.c @@ -138,7 +138,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = strlen(connp->cert0_issuerdn); + const uint32_t data_len = (uint32_t)strlen(connp->cert0_issuerdn); const uint8_t *data = (uint8_t *)connp->cert0_issuerdn; InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-tls-cert-serial.c b/src/detect-tls-cert-serial.c index 7d7628fd83..ceb8f1d4a8 100644 --- a/src/detect-tls-cert-serial.c +++ b/src/detect-tls-cert-serial.c @@ -148,7 +148,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = strlen(connp->cert0_serial); + const uint32_t data_len = (uint32_t)strlen(connp->cert0_serial); const uint8_t *data = (uint8_t *)connp->cert0_serial; InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-tls-cert-subject.c b/src/detect-tls-cert-subject.c index 4cc3e17aeb..0e925f7392 100644 --- a/src/detect-tls-cert-subject.c +++ b/src/detect-tls-cert-subject.c @@ -140,7 +140,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = strlen(connp->cert0_subject); + const uint32_t data_len = (uint32_t)strlen(connp->cert0_subject); const uint8_t *data = (uint8_t *)connp->cert0_subject; InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-tls-ja3-hash.c b/src/detect-tls-ja3-hash.c index 1daf66a193..22fcee1d26 100644 --- a/src/detect-tls-ja3-hash.c +++ b/src/detect-tls-ja3-hash.c @@ -165,7 +165,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = strlen(ssl_state->client_connp.ja3_hash); + const uint32_t data_len = (uint32_t)strlen(ssl_state->client_connp.ja3_hash); const uint8_t *data = (uint8_t *)ssl_state->client_connp.ja3_hash; InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-tls-ja3-string.c b/src/detect-tls-ja3-string.c index 3a0400fb04..e20e222414 100644 --- a/src/detect-tls-ja3-string.c +++ b/src/detect-tls-ja3-string.c @@ -159,7 +159,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = strlen(ssl_state->client_connp.ja3_str->data); + const uint32_t data_len = (uint32_t)strlen(ssl_state->client_connp.ja3_str->data); const uint8_t *data = (uint8_t *)ssl_state->client_connp.ja3_str->data; InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-tls-ja3s-hash.c b/src/detect-tls-ja3s-hash.c index ebfd7cb114..0270f738bc 100644 --- a/src/detect-tls-ja3s-hash.c +++ b/src/detect-tls-ja3s-hash.c @@ -163,7 +163,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = strlen(ssl_state->server_connp.ja3_hash); + const uint32_t data_len = (uint32_t)strlen(ssl_state->server_connp.ja3_hash); const uint8_t *data = (uint8_t *)ssl_state->server_connp.ja3_hash; InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-tls-ja3s-string.c b/src/detect-tls-ja3s-string.c index fd1340a2f0..2d7aa3a984 100644 --- a/src/detect-tls-ja3s-string.c +++ b/src/detect-tls-ja3s-string.c @@ -158,7 +158,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = strlen(ssl_state->server_connp.ja3_str->data); + const uint32_t data_len = (uint32_t)strlen(ssl_state->server_connp.ja3_str->data); const uint8_t *data = (uint8_t *)ssl_state->server_connp.ja3_str->data; InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-tls-sni.c b/src/detect-tls-sni.c index b7e58d7aa6..4afd5daffb 100644 --- a/src/detect-tls-sni.c +++ b/src/detect-tls-sni.c @@ -120,7 +120,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return NULL; } - const uint32_t data_len = strlen(ssl_state->client_connp.sni); + const uint32_t data_len = (uint32_t)strlen(ssl_state->client_connp.sni); const uint8_t *data = (uint8_t *)ssl_state->client_connp.sni; InspectionBufferSetupAndApplyTransforms( diff --git a/src/detect-tls-subjectaltname.c b/src/detect-tls-subjectaltname.c index 7e535165c8..06231d14f7 100644 --- a/src/detect-tls-subjectaltname.c +++ b/src/detect-tls-subjectaltname.c @@ -68,7 +68,7 @@ static bool TlsSubjectAltNameGetData(DetectEngineThreadCtx *det_ctx, const void } *buf = (const uint8_t *)connp->cert0_sans[idx]; - *buf_len = strlen(connp->cert0_sans[idx]); + *buf_len = (uint32_t)strlen(connp->cert0_sans[idx]); return true; } diff --git a/src/detect.c b/src/detect.c index ffa1ee09cd..7e60124f23 100644 --- a/src/detect.c +++ b/src/detect.c @@ -294,7 +294,7 @@ static inline void DetectPrefilterCopyDeDup(DetectEngineCtx *de_ctx, DetectEngin } } - det_ctx->match_array_cnt = match_array - det_ctx->match_array; + det_ctx->match_array_cnt = (uint32_t)(match_array - det_ctx->match_array); DEBUG_VALIDATE_BUG_ON(det_ctx->pmq.rule_id_array_cnt < det_ctx->match_array_cnt); PMQ_RESET(&det_ctx->pmq); }