]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: fix integer warnings
authorPhilippe Antoine <contact@catenacyber.fr>
Tue, 18 Jan 2022 15:11:37 +0000 (16:11 +0100)
committerVictor Julien <vjulien@oisf.net>
Thu, 9 Jun 2022 05:27:16 +0000 (07:27 +0200)
Ticket: #4516

39 files changed:
src/decode-icmpv4.h
src/detect-byte-extract.c
src/detect-byte-extract.h
src/detect-bytejump.c
src/detect-cipservice.c
src/detect-csum.c
src/detect-dnp3.c
src/detect-engine-address.c
src/detect-engine-alert.c
src/detect-engine-analyzer.c
src/detect-engine-analyzer.h
src/detect-engine-build.c
src/detect-engine-content-inspection.c
src/detect-engine-event.c
src/detect-engine-iponly.c
src/detect-engine-mpm.c
src/detect-engine-port.c
src/detect-engine-prefilter.c
src/detect-engine.c
src/detect-file-hash-common.c
src/detect-file-hash-common.h
src/detect-flow.c
src/detect-flowvar.h
src/detect-ftpbounce.c
src/detect-http2.c
src/detect-id.c
src/detect-ipproto.c
src/detect-metadata.c
src/detect-pcre.c
src/detect-pktvar.h
src/detect-ssh-proto-version.c
src/detect-ssh-software-version.c
src/detect-ssl-version.c
src/detect-tag.h
src/detect-transform-urldecode.c
src/detect-transform-xor.c
src/detect-urilen.c
src/detect.c
src/detect.h

index ed1f657013a1b83f8e37046431a48eff43f16563..ed24fce06665fa19d6c04c8f740b63bbbd7dc628 100644 (file)
@@ -187,7 +187,7 @@ typedef struct ICMPV4Vars_
     uint16_t  seq;
 
     /** Actual header length **/
-    uint32_t hlen;
+    uint16_t hlen;
 
     /** Pointers to the embedded packet headers */
     IPV4Hdr *emb_ipv4h;
index 7c1ba2182a4fe4c42916ade747b5065e705cdc56..b96c43b225e8bc0b0c47b0dc4e1ddce95b4061d1 100644 (file)
@@ -112,9 +112,8 @@ void DetectByteExtractRegister(void)
 }
 
 int DetectByteExtractDoMatch(DetectEngineThreadCtx *det_ctx, const SigMatchData *smd,
-                             const Signature *s, const uint8_t *payload,
-                             uint16_t payload_len, uint64_t *value,
-                             uint8_t endian)
+        const Signature *s, const uint8_t *payload, uint32_t payload_len, uint64_t *value,
+        uint8_t endian)
 {
     DetectByteExtractData *data = (DetectByteExtractData *)smd->ctx;
     const uint8_t *ptr = NULL;
@@ -320,11 +319,10 @@ static inline DetectByteExtractData *DetectByteExtractParse(DetectEngineCtx *de_
                         i);
                 goto error;
             }
-            int32_t multiplier;
-            if (StringParseI32RangeCheck(&multiplier, 10, 0,
-                                 (const char *)multiplier_str,
-                                 DETECT_BYTE_EXTRACT_MULTIPLIER_MIN_LIMIT,
-                                 DETECT_BYTE_EXTRACT_MULTIPLIER_MAX_LIMIT) < 0) {
+            uint16_t multiplier;
+            if (StringParseU16RangeCheck(&multiplier, 10, 0, (const char *)multiplier_str,
+                        DETECT_BYTE_EXTRACT_MULTIPLIER_MIN_LIMIT,
+                        DETECT_BYTE_EXTRACT_MULTIPLIER_MAX_LIMIT) < 0) {
                 SCLogError(SC_ERR_INVALID_SIGNATURE, "Invalid value for"
                         "multiplier: \"%s\".", multiplier_str);
                 goto error;
index 7fff95a59e317cbf42bfd065659963ec83bdde2f..71b433d3405f9be46de8714f631cc956fd00388a 100644 (file)
@@ -63,6 +63,6 @@ void DetectByteExtractRegister(void);
 
 SigMatch *DetectByteExtractRetrieveSMVar(const char *, const Signature *);
 int DetectByteExtractDoMatch(DetectEngineThreadCtx *, const SigMatchData *, const Signature *,
-                             const uint8_t *, uint16_t, uint64_t *, uint8_t);
+        const uint8_t *, uint32_t, uint64_t *, uint8_t);
 
 #endif /* __DETECT_BYTEEXTRACT_H__ */
index 0d3694f25a592b6c5b6a65d5a8eeba44f22ee293..02072bab57f681e8fb2d2d465de93461ef27135a 100644 (file)
@@ -40,6 +40,7 @@
 #include "util-byte.h"
 #include "util-unittest.h"
 #include "util-debug.h"
+#include "util-validate.h"
 #include "detect-pcre.h"
 
 /**
@@ -221,7 +222,8 @@ static int DetectBytejumpMatch(DetectEngineThreadCtx *det_ctx,
      */
     if (data->flags & DETECT_BYTEJUMP_RELATIVE) {
         ptr = p->payload + det_ctx->buffer_offset;
-        len = p->payload_len - det_ctx->buffer_offset;
+        DEBUG_VALIDATE_BUG_ON(p->payload_len - det_ctx->buffer_offset > UINT16_MAX);
+        len = (uint16_t)(p->payload_len - det_ctx->buffer_offset);
 
         /* No match if there is no relative base */
         if (ptr == NULL || len == 0) {
@@ -233,7 +235,8 @@ static int DetectBytejumpMatch(DetectEngineThreadCtx *det_ctx,
     }
     else {
         ptr = p->payload + data->offset;
-        len = p->payload_len - data->offset;
+        DEBUG_VALIDATE_BUG_ON(p->payload_len - data->offset > UINT16_MAX);
+        len = (uint16_t)(p->payload_len - data->offset);
     }
 
     /* Verify the to-be-extracted data is within the packet */
@@ -395,7 +398,7 @@ static DetectBytejumpData *DetectBytejumpParse(DetectEngineCtx *de_ctx, const ch
      */
 
     /* Number of bytes */
-    if (StringParseUint32(&nbytes, 10, strlen(args[0]), args[0]) <= 0) {
+    if (StringParseUint32(&nbytes, 10, (uint16_t)strlen(args[0]), args[0]) <= 0) {
         SCLogError(SC_ERR_INVALID_VALUE, "Malformed number of bytes: %s", optstr);
         goto error;
     }
@@ -412,7 +415,7 @@ static DetectBytejumpData *DetectBytejumpParse(DetectEngineCtx *de_ctx, const ch
         if (*offset == NULL)
             goto error;
     } else {
-        if (StringParseInt32(&data->offset, 0, strlen(args[1]), args[1]) <= 0) {
+        if (StringParseInt32(&data->offset, 0, (uint16_t)strlen(args[1]), args[1]) <= 0) {
             SCLogError(SC_ERR_INVALID_VALUE, "Malformed offset: %s", optstr);
             goto error;
         }
@@ -445,18 +448,14 @@ static DetectBytejumpData *DetectBytejumpParse(DetectEngineCtx *de_ctx, const ch
         } else if (strcasecmp("align", args[i]) == 0) {
             data->flags |= DETECT_BYTEJUMP_ALIGN;
         } else if (strncasecmp("multiplier ", args[i], 11) == 0) {
-            if (StringParseUint32(&data->multiplier, 10,
-                                        strlen(args[i]) - 11,
-                                        args[i] + 11) <= 0)
-            {
+            if (StringParseUint32(
+                        &data->multiplier, 10, (uint16_t)strlen(args[i]) - 11, args[i] + 11) <= 0) {
                 SCLogError(SC_ERR_INVALID_VALUE, "Malformed multiplier: %s", optstr);
                 goto error;
             }
         } else if (strncasecmp("post_offset ", args[i], 12) == 0) {
-            if (StringParseInt32(&data->post_offset, 10,
-                                       strlen(args[i]) - 12,
-                                       args[i] + 12) <= 0)
-            {
+            if (StringParseInt32(&data->post_offset, 10, (uint16_t)strlen(args[i]) - 12,
+                        args[i] + 12) <= 0) {
                 SCLogError(SC_ERR_INVALID_VALUE, "Malformed post_offset: %s", optstr);
                 goto error;
             }
index 482fc56fa29b11359e48c3afb3ec0c6303c6cd52..1841bfc06b492289299a471a3f0d2dbaa35ba892 100644 (file)
@@ -104,9 +104,9 @@ static DetectCipServiceData *DetectCipServiceParse(const char *rulestrc)
 
     char* token;
     char *save;
-    int var;
-    int input[3] = { 0, 0, 0 };
-    int i = 0;
+    uint8_t var;
+    uint8_t input[3] = { 0, 0, 0 };
+    uint8_t i = 0;
 
     token = strtok_r(rulestr, delims, &save);
     while (token != NULL)
@@ -156,7 +156,7 @@ static DetectCipServiceData *DetectCipServiceParse(const char *rulestrc)
             goto error;
         }
 
-        sscanf(token, "%d", &var);
+        sscanf(token, "%2" SCNu8, &var);
         input[i++] = var;
 
         token = strtok_r(NULL, delims, &save);
index bc765cd7ebbbe96b69762445d42b166554b14a69..ed4e58d854d9da63ae872f0f8effbcce64231925 100644 (file)
@@ -819,7 +819,7 @@ static int DetectICMPV6CsumMatch(DetectEngineThreadCtx *det_ctx,
 
     if (p->level4_comp_csum == -1) {
         uint16_t len = IPV6_GET_RAW_PLEN(p->ip6h) -
-            ((uint8_t *)p->icmpv6h - (uint8_t *)p->ip6h - IPV6_HEADER_LEN);
+                       (uint16_t)((uint8_t *)p->icmpv6h - (uint8_t *)p->ip6h - IPV6_HEADER_LEN);
         p->level4_comp_csum = ICMPV6CalculateChecksum(p->ip6h->s_ip6_addrs,
                                                       (uint16_t *)p->icmpv6h,
                                                       len);
index be256b34b1043aaac86d8766cd884c441d4e05f6..fa54c8d42f00c9c3f1eda28279dedc6c9168f2f2 100644 (file)
@@ -196,7 +196,7 @@ static int DetectEngineInspectDNP3(DetectEngineCtx *de_ctx, DetectEngineThreadCt
  */
 static int DetectDNP3FuncParseFunctionCode(const char *str, uint8_t *fc)
 {
-    if (StringParseUint8(fc, 10, strlen(str), str) >= 0) {
+    if (StringParseUint8(fc, 10, (uint16_t)strlen(str), str) >= 0) {
         return 1;
     }
 
@@ -204,7 +204,7 @@ static int DetectDNP3FuncParseFunctionCode(const char *str, uint8_t *fc)
     for (size_t i = 0;
             i < sizeof(DNP3FunctionNameMap) / sizeof(DNP3Mapping); i++) {
         if (strcasecmp(str, DNP3FunctionNameMap[i].name) == 0) {
-            *fc = DNP3FunctionNameMap[i].value;
+            *fc = (uint8_t)(DNP3FunctionNameMap[i].value);
             return 1;
         }
     }
@@ -288,7 +288,7 @@ static int DetectDNP3IndParse(const char *str, uint16_t *flags)
 {
     *flags = 0;
 
-    if (StringParseUint16(flags, 0, strlen(str), str) > 0) {
+    if (StringParseUint16(flags, 0, (uint16_t)strlen(str), str) > 0) {
         return 1;
     }
 
@@ -363,11 +363,11 @@ static int DetectDNP3ObjParse(const char *str, uint8_t *group, uint8_t *var)
     *sep = '\0';
     varstr = sep + 1;
 
-    if (StringParseUint8(group, 0, strlen(groupstr), groupstr) < 0) {
+    if (StringParseUint8(group, 0, (uint16_t)strlen(groupstr), groupstr) < 0) {
         return 0;
     }
 
-    if (StringParseUint8(var, 0, strlen(varstr), varstr) < 0) {
+    if (StringParseUint8(var, 0, (uint16_t)strlen(varstr), varstr) < 0) {
         return 0;
     }
 
index 1dc6bcfaca50fa78ba022d4f4ad6f792866fc360..4d5bc434f0b51210bde6e1690d412cbf8ea6f768 100644 (file)
@@ -1330,8 +1330,7 @@ static char DetectAddressMapCompareFunc(void *data1, uint16_t len1, void *data2,
     DetectAddressMap *map1 = (DetectAddressMap *)data1;
     DetectAddressMap *map2 = (DetectAddressMap *)data2;
 
-
-    int r = (strcmp(map1->string, map2->string) == 0);
+    char r = (strcmp(map1->string, map2->string) == 0);
     return r;
 }
 
index 273604e4bd2c96a63ebca40f5173fbbeb52571a1..1e5c7127300030be5d215147daa7318978db0c4f 100644 (file)
@@ -336,12 +336,12 @@ void PacketAlertFinalize(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx
     qsort(det_ctx->alert_queue, det_ctx->alert_queue_size, sizeof(PacketAlert),
             AlertQueueSortHelper);
 
-    int i = 0;
+    uint16_t i = 0;
     uint16_t max_pos = det_ctx->alert_queue_size;
 
     while (i < max_pos) {
         const Signature *s = de_ctx->sig_array[det_ctx->alert_queue[i].num];
-        uint8_t res = PacketAlertHandle(de_ctx, det_ctx, s, p, &det_ctx->alert_queue[i]);
+        int res = PacketAlertHandle(de_ctx, det_ctx, s, p, &det_ctx->alert_queue[i]);
 
         if (res > 0) {
             /* Now, if we have an alert, we have to check if we want
index 5bfe46cd2faddc695ddb8e160d8a3754503e3e2a..103bbc8f713b61aa6ad2a90dcdbcb8554f868ad8 100644 (file)
@@ -38,6 +38,7 @@
 #include "detect-tcp-flags.h"
 #include "feature.h"
 #include "util-print.h"
+#include "util-validate.h"
 
 static int rule_warnings_only = 0;
 static FILE *rule_engine_analysis_FD = NULL;
@@ -457,7 +458,7 @@ int PerCentEncodingSetup ()
  * \retval 0 if it doesn't have % encoding
  * \retval -1 on error
  */
-int PerCentEncodingMatch (uint8_t *content, uint8_t content_len)
+static int PerCentEncodingMatch(uint8_t *content, uint16_t content_len)
 {
     int ret = 0;
 
@@ -1073,7 +1074,9 @@ static void EngineAnalysisItemsInit(void)
     for (size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
         DetectEngineAnalyzerItems *analyzer_item = &analyzer_items[i];
 
-        analyzer_item->item_id = DetectBufferTypeGetByName(analyzer_item->item_name);
+        int item_id = DetectBufferTypeGetByName(analyzer_item->item_name);
+        DEBUG_VALIDATE_BUG_ON(item_id < 0 || item_id > UINT16_MAX);
+        analyzer_item->item_id = (uint16_t)item_id;
         if (analyzer_item->item_id == -1) {
             /* Mismatch between the analyzer_items array and what's supported */
             FatalError(SC_ERR_INITIALIZATION,
index 7b8af5deba34787230d3084c099eb06d55b8133f..7bf5225823866fac4805b07127e40fffef7ed61e 100644 (file)
@@ -33,7 +33,6 @@ int SetupRuleAnalyzer(void);
 void CleanupRuleAnalyzer (void);
 
 int PerCentEncodingSetup (void);
-int PerCentEncodingMatch (uint8_t *content, uint8_t content_len);
 
 void EngineAnalysisFP(const DetectEngineCtx *de_ctx,
         const Signature *s, char *line);
index 0367cf64bc6c26f862abfefbc8eb9db31339033a..b9fb4ca6c79da9bedf19b0db05f60df2e4ba8e86 100644 (file)
@@ -830,7 +830,7 @@ static json_t *RulesGroupPrintSghStats(const DetectEngineCtx *de_ctx, const SigG
     json_object_set_new(types, "any5", json_integer(any5_cnt));
     json_object_set_new(stats, "types", types);
 
-    for (int i = 0; i < ALPROTO_MAX; i++) {
+    for (AppProto i = 0; i < ALPROTO_MAX; i++) {
         if (alstats[i] > 0) {
             json_t *app = json_object();
             json_object_set_new(app, "total", json_integer(alstats[i]));
@@ -1178,7 +1178,8 @@ static int RuleSetWhitelist(Signature *s)
 int CreateGroupedPortList(DetectEngineCtx *de_ctx, DetectPort *port_list, DetectPort **newhead, uint32_t unique_groups, int (*CompareFunc)(DetectPort *, DetectPort *), uint32_t max_idx);
 int CreateGroupedPortListCmpCnt(DetectPort *a, DetectPort *b);
 
-static DetectPort *RulesGroupByPorts(DetectEngineCtx *de_ctx, int ipproto, uint32_t direction) {
+static DetectPort *RulesGroupByPorts(DetectEngineCtx *de_ctx, uint8_t ipproto, uint32_t direction)
+{
     /* step 1: create a hash of 'DetectPort' objects based on all the
      *         rules. Each object will have a SGH with the sigs added
      *         that belong to the SGH. */
index ba2d43f8a31fc3ee01831e1981b17d47804000f5..a34b4922221b4543ca170e2a5054f5157d60fd85 100644 (file)
@@ -52,6 +52,7 @@
 #include "util-spm.h"
 #include "util-debug.h"
 #include "util-print.h"
+#include "util-validate.h"
 
 #include "util-unittest.h"
 #include "util-unittest-helper.h"
@@ -527,10 +528,8 @@ int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx
                        DETECT_BYTE_EXTRACT_ENDIAN_LITTLE : DETECT_BYTE_EXTRACT_ENDIAN_BIG);
         }
 
-        if (DetectByteExtractDoMatch(det_ctx, smd, s, buffer,
-                                     buffer_len,
-                                     &det_ctx->byte_values[bed->local_id],
-                                     endian) != 1) {
+        if (DetectByteExtractDoMatch(det_ctx, smd, s, buffer, buffer_len,
+                    &det_ctx->byte_values[bed->local_id], endian) != 1) {
             goto no_match;
         }
 
@@ -561,12 +560,9 @@ int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx
              rvalue = bmd->rvalue;
         }
 
-
-        if (DetectByteMathDoMatch(det_ctx, smd, s, buffer,
-                                     buffer_len,
-                                     rvalue,
-                                     &det_ctx->byte_values[bmd->local_id],
-                                     endian) != 1) {
+        DEBUG_VALIDATE_BUG_ON(buffer_len > UINT16_MAX);
+        if (DetectByteMathDoMatch(det_ctx, smd, s, buffer, (uint16_t)buffer_len, rvalue,
+                    &det_ctx->byte_values[bmd->local_id], endian) != 1) {
             goto no_match;
         }
 
index 191fecb40f580d2bb7a9d8e6002a617b4e46431e..fb9e98b59e52374ddbac424756ab8983ee35f37d 100644 (file)
@@ -181,8 +181,8 @@ error:
  * \retval 0 on Success
  * \retval -1 on Failure
  */
-static int DetectEngineEventSetupDo (DetectEngineCtx *de_ctx, Signature *s,
-        const char *rawstr, int smtype)
+static int DetectEngineEventSetupDo(
+        DetectEngineCtx *de_ctx, Signature *s, const char *rawstr, uint16_t smtype)
 {
     DetectEngineEventData *de = DetectEngineEventParse(rawstr);
     if (de == NULL)
index ee81c2688f27decd25020faa6726dc07e0332722..29c98cc80237e9343b698b269a38472ecbaa2a75 100644 (file)
@@ -216,8 +216,8 @@ static int IPOnlyCIDRItemParseSingle(IPOnlyCIDRItem **pdd, const char *str)
                         goto error;
                 }
 
-                int cidr;
-                if (StringParseI32RangeCheck(&cidr, 10, 0, (const char *)mask, 0, 32) < 0)
+                uint8_t cidr;
+                if (StringParseU8RangeCheck(&cidr, 10, 0, (const char *)mask, 0, 32) < 0)
                     goto error;
 
                 dd->netmask = cidr;
@@ -1170,7 +1170,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                     SigNumArray *sna = SigNumArrayNew(de_ctx, &de_ctx->io_ctx);
 
                     /* Update the sig */
-                    uint8_t tmp = 1 << (src->signum % 8);
+                    uint8_t tmp = (uint8_t)(1 << (src->signum % 8));
 
                     if (src->negated > 0)
                         /* Unset it */
@@ -1198,7 +1198,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                     sna = SigNumArrayCopy((SigNumArray *) user_data);
 
                     /* Update the sig */
-                    uint8_t tmp = 1 << (src->signum % 8);
+                    uint8_t tmp = (uint8_t)(1 << (src->signum % 8));
 
                     if (src->negated > 0)
                         /* Unset it */
@@ -1231,7 +1231,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                 SigNumArray *sna = (SigNumArray *)user_data;
 
                 /* Update the sig */
-                uint8_t tmp = 1 << (src->signum % 8);
+                uint8_t tmp = (uint8_t)(1 << (src->signum % 8));
 
                 if (src->negated > 0)
                     /* Unset it */
@@ -1264,7 +1264,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                     SigNumArray *sna = SigNumArrayNew(de_ctx, &de_ctx->io_ctx);
 
                     /* Update the sig */
-                    uint8_t tmp = 1 << (src->signum % 8);
+                    uint8_t tmp = (uint8_t)(1 << (src->signum % 8));
 
                     if (src->negated > 0)
                         /* Unset it */
@@ -1289,7 +1289,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                     sna = SigNumArrayCopy((SigNumArray *)user_data);
 
                     /* Update the sig */
-                    uint8_t tmp = 1 << (src->signum % 8);
+                    uint8_t tmp = (uint8_t)(1 << (src->signum % 8));
                     if (src->negated > 0)
                         /* Unset it */
                         sna->array[src->signum / 8] &= ~tmp;
@@ -1313,7 +1313,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                 SigNumArray *sna = (SigNumArray *)user_data;
 
                 /* Update the sig */
-                uint8_t tmp = 1 << (src->signum % 8);
+                uint8_t tmp = (uint8_t)(1 << (src->signum % 8));
                 if (src->negated > 0)
                     /* Unset it */
                     sna->array[src->signum / 8] &= ~tmp;
@@ -1366,7 +1366,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                     SigNumArray *sna = SigNumArrayNew(de_ctx, &de_ctx->io_ctx);
 
                     /** Update the sig */
-                    uint8_t tmp = 1 << (dst->signum % 8);
+                    uint8_t tmp = (uint8_t)(1 << (dst->signum % 8));
                     if (dst->negated > 0)
                         /** Unset it */
                         sna->array[dst->signum / 8] &= ~tmp;
@@ -1393,7 +1393,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                     sna = SigNumArrayCopy((SigNumArray *) user_data);
 
                     /* Update the sig */
-                    uint8_t tmp = 1 << (dst->signum % 8);
+                    uint8_t tmp = (uint8_t)(1 << (dst->signum % 8));
                     if (dst->negated > 0)
                         /* Unset it */
                         sna->array[dst->signum / 8] &= ~tmp;
@@ -1420,7 +1420,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                 SigNumArray *sna = (SigNumArray *)user_data;
 
                 /* Update the sig */
-                uint8_t tmp = 1 << (dst->signum % 8);
+                uint8_t tmp = (uint8_t)(1 << (dst->signum % 8));
                 if (dst->negated > 0)
                     /* Unset it */
                     sna->array[dst->signum / 8] &= ~tmp;
@@ -1454,7 +1454,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                     SigNumArray *sna = SigNumArrayNew(de_ctx, &de_ctx->io_ctx);
 
                     /* Update the sig */
-                    uint8_t tmp = 1 << (dst->signum % 8);
+                    uint8_t tmp = (uint8_t)(1 << (dst->signum % 8));
                     if (dst->negated > 0)
                         /* Unset it */
                         sna->array[dst->signum / 8] &= ~tmp;
@@ -1479,7 +1479,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                     sna = SigNumArrayCopy((SigNumArray *)user_data);
 
                     /* Update the sig */
-                    uint8_t tmp = 1 << (dst->signum % 8);
+                    uint8_t tmp = (uint8_t)(1 << (dst->signum % 8));
                     if (dst->negated > 0)
                         /* Unset it */
                         sna->array[dst->signum / 8] &= ~tmp;
@@ -1504,7 +1504,7 @@ void IPOnlyPrepare(DetectEngineCtx *de_ctx)
                 SigNumArray *sna = (SigNumArray *)user_data;
 
                 /* Update the sig */
-                uint8_t tmp = 1 << (dst->signum % 8);
+                uint8_t tmp = (uint8_t)(1 << (dst->signum % 8));
                 if (dst->negated > 0)
                     /* Unset it */
                     sna->array[dst->signum / 8] &= ~tmp;
index 9d126c7ed6007919385b5e9c16a68efa569c7331..c6abe9417369892c1531866c84439a1fd4b5613d 100644 (file)
@@ -118,8 +118,8 @@ void DetectAppLayerMpmRegister2(const char *name,
     snprintf(am->pname, sizeof(am->pname), "%s", am->name);
     am->direction = direction;
     DEBUG_VALIDATE_BUG_ON(sm_list < 0 || sm_list > INT16_MAX);
-    am->sm_list = sm_list;
-    am->sm_list_base = sm_list;
+    am->sm_list = (int16_t)sm_list;
+    am->sm_list_base = (int16_t)sm_list;
     am->priority = priority;
     am->type = DETECT_BUFFER_MPM_TYPE_APP;
 
@@ -159,7 +159,7 @@ void DetectAppLayerMpmRegisterByParentId(DetectEngineCtx *de_ctx,
             am->name = t->name;
             am->direction = t->direction;
             DEBUG_VALIDATE_BUG_ON(id < 0 || id > INT16_MAX);
-            am->sm_list = id; // use new id
+            am->sm_list = (uint16_t)id; // use new id
             am->sm_list_base = t->sm_list;
             am->type = DETECT_BUFFER_MPM_TYPE_APP;
             am->PrefilterRegisterWithListId = t->PrefilterRegisterWithListId;
@@ -302,7 +302,7 @@ void DetectFrameMpmRegister(const char *name, int direction, int priority,
     DetectBufferTypeSupportsFrames(name);
     DetectBufferTypeSupportsTransformations(name);
     int sm_list = DetectBufferTypeGetByName(name);
-    if (sm_list == -1) {
+    if (sm_list < 0 || sm_list > UINT16_MAX) {
         FatalError(SC_ERR_INITIALIZATION, "MPM engine registration for %s failed", name);
     }
 
@@ -310,7 +310,7 @@ void DetectFrameMpmRegister(const char *name, int direction, int priority,
     BUG_ON(am == NULL);
     am->name = name;
     snprintf(am->pname, sizeof(am->pname), "%s", am->name);
-    am->sm_list = sm_list;
+    am->sm_list = (uint16_t)sm_list;
     am->direction = direction;
     am->priority = priority;
     am->type = DETECT_BUFFER_MPM_TYPE_FRAME;
@@ -350,7 +350,8 @@ void DetectFrameMpmRegisterByParentId(DetectEngineCtx *de_ctx, const int id, con
             BUG_ON(am == NULL);
             am->name = t->name;
             snprintf(am->pname, sizeof(am->pname), "%s#%d", am->name, id);
-            am->sm_list = id; // use new id
+            DEBUG_VALIDATE_BUG_ON(id < 0 || id > UINT16_MAX);
+            am->sm_list = (uint16_t)id; // use new id
             am->sm_list_base = t->sm_list;
             am->type = DETECT_BUFFER_MPM_TYPE_FRAME;
             am->PrefilterRegisterWithListId = t->PrefilterRegisterWithListId;
@@ -386,7 +387,7 @@ void DetectEngineFrameMpmRegister(DetectEngineCtx *de_ctx, const char *name, int
             AppProtoToString(alproto), type);
 
     const int sm_list = DetectEngineBufferTypeRegister(de_ctx, name);
-    if (sm_list < 0) {
+    if (sm_list < 0 || sm_list > UINT16_MAX) {
         FatalError(SC_ERR_INITIALIZATION, "MPM engine registration for %s failed", name);
     }
 
@@ -398,7 +399,7 @@ void DetectEngineFrameMpmRegister(DetectEngineCtx *de_ctx, const char *name, int
     BUG_ON(am == NULL);
     am->name = name;
     snprintf(am->pname, sizeof(am->pname), "%s", am->name);
-    am->sm_list = sm_list;
+    am->sm_list = (uint16_t)sm_list;
     am->direction = direction;
     am->priority = priority;
     am->type = DETECT_BUFFER_MPM_TYPE_FRAME;
@@ -549,7 +550,7 @@ void DetectPktMpmRegister(const char *name,
     am->name = name;
     snprintf(am->pname, sizeof(am->pname), "%s", am->name);
     DEBUG_VALIDATE_BUG_ON(sm_list < 0 || sm_list > INT16_MAX);
-    am->sm_list = sm_list;
+    am->sm_list = (uint16_t)sm_list;
     am->priority = priority;
     am->type = DETECT_BUFFER_MPM_TYPE_PKT;
 
@@ -587,7 +588,7 @@ void DetectPktMpmRegisterByParentId(DetectEngineCtx *de_ctx,
             am->name = t->name;
             snprintf(am->pname, sizeof(am->pname), "%s#%d", am->name, id);
             DEBUG_VALIDATE_BUG_ON(id < 0 || id > INT16_MAX);
-            am->sm_list = id; // use new id
+            am->sm_list = (uint16_t)id; // use new id
             am->sm_list_base = t->sm_list;
             am->type = DETECT_BUFFER_MPM_TYPE_PKT;
             am->PrefilterRegisterWithListId = t->PrefilterRegisterWithListId;
@@ -869,7 +870,7 @@ uint8_t PatternMatchDefaultMatcher(void)
             if (strcmp("auto", mpm_algo) == 0) {
                 goto done;
             }
-            for (uint16_t u = 0; u < MPM_TABLE_SIZE; u++) {
+            for (uint8_t u = 0; u < MPM_TABLE_SIZE; u++) {
                 if (mpm_table[u].name == NULL)
                     continue;
 
index c1e1cec3ef3a1fe7cd9237bb61fca39e5d20d169..29d649b8f15790b072b6e4fe0cca11d4ff1a2646 100644 (file)
@@ -260,10 +260,10 @@ error:
 static int DetectPortCut(DetectEngineCtx *de_ctx, DetectPort *a,
                          DetectPort *b, DetectPort **c)
 {
-    uint32_t a_port1 = a->port;
-    uint32_t a_port2 = a->port2;
-    uint32_t b_port1 = b->port;
-    uint32_t b_port2 = b->port2;
+    uint16_t a_port1 = a->port;
+    uint16_t a_port2 = a->port2;
+    uint16_t b_port1 = b->port;
+    uint16_t b_port2 = b->port2;
 
     /* default to NULL */
     *c = NULL;
index 3173287731fb32c21575d8c515af3898638c797d..54e2a241f850fa1b80eae21a61f93a0b9a14f504 100644 (file)
@@ -286,7 +286,9 @@ int PrefilterAppendTxEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh,
     e->PrefilterTx = PrefilterTxFunc;
     e->pectx = pectx;
     e->alproto = alproto;
-    e->tx_min_progress = tx_min_progress;
+    // TODO change function prototype ?
+    DEBUG_VALIDATE_BUG_ON(tx_min_progress > UINT8_MAX);
+    e->tx_min_progress = (uint8_t)tx_min_progress;
     e->Free = FreeFunc;
 
     if (sgh->init->tx_engines == NULL) {
@@ -498,7 +500,7 @@ void PrefilterSetupRuleGroup(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
         }
         memset(sgh->tx_engines, 0x00, (cnt * sizeof(PrefilterEngine)));
 
-        uint32_t local_id = 0;
+        uint16_t local_id = 0;
         PrefilterEngine *e = sgh->tx_engines;
         for (el = sgh->init->tx_engines ; el != NULL; el = el->next) {
             e->local_id = local_id++;
index 07181181d9d1457759fc2a3d86665a5eb468b407..b969db79b4d113eb62af0d215974c23c3260f651 100644 (file)
@@ -154,8 +154,8 @@ void DetectPktInspectEngineRegister(const char *name,
         FatalError(SC_ERR_INITIALIZATION,
             "failed to register inspect engine %s: %s", name, strerror(errno));
     }
-    new_engine->sm_list = sm_list;
-    new_engine->sm_list_base = sm_list;
+    new_engine->sm_list = (uint16_t)sm_list;
+    new_engine->sm_list_base = (uint16_t)sm_list;
     new_engine->v1.Callback = Callback;
     new_engine->v1.GetData = GetPktData;
 
@@ -188,7 +188,7 @@ void DetectFrameInspectEngineRegister(const char *name, int dir,
         BUG_ON(1);
     }
 
-    int direction;
+    uint8_t direction;
     if (dir == SIG_FLAG_TOSERVER) {
         direction = 0;
     } else {
@@ -200,8 +200,8 @@ void DetectFrameInspectEngineRegister(const char *name, int dir,
         FatalError(SC_ERR_INITIALIZATION, "failed to register inspect engine %s: %s", name,
                 strerror(errno));
     }
-    new_engine->sm_list = sm_list;
-    new_engine->sm_list_base = sm_list;
+    new_engine->sm_list = (uint16_t)sm_list;
+    new_engine->sm_list_base = (uint16_t)sm_list;
     new_engine->dir = direction;
     new_engine->v1.Callback = Callback;
     new_engine->alproto = alproto;
@@ -250,7 +250,7 @@ void DetectAppLayerInspectEngineRegister2(const char *name,
         BUG_ON(1);
     }
 
-    int direction;
+    uint8_t direction;
     if (dir == SIG_FLAG_TOSERVER) {
         direction = 0;
     } else {
@@ -264,9 +264,9 @@ void DetectAppLayerInspectEngineRegister2(const char *name,
     memset(new_engine, 0, sizeof(*new_engine));
     new_engine->alproto = alproto;
     new_engine->dir = direction;
-    new_engine->sm_list = sm_list;
-    new_engine->sm_list_base = sm_list;
-    new_engine->progress = progress;
+    new_engine->sm_list = (uint16_t)sm_list;
+    new_engine->sm_list_base = (uint16_t)sm_list;
+    new_engine->progress = (int16_t)progress;
     new_engine->v2.Callback = Callback2;
     new_engine->v2.GetData = GetData;
 
@@ -297,8 +297,10 @@ static void DetectAppLayerInspectEngineCopy(
             }
             new_engine->alproto = t->alproto;
             new_engine->dir = t->dir;
-            new_engine->sm_list = new_list;         /* use new list id */
-            new_engine->sm_list_base = sm_list;
+            DEBUG_VALIDATE_BUG_ON(new_list < 0 || new_list > UINT16_MAX);
+            new_engine->sm_list = (uint16_t)new_list; /* use new list id */
+            DEBUG_VALIDATE_BUG_ON(sm_list < 0 || sm_list > UINT16_MAX);
+            new_engine->sm_list_base = (uint16_t)sm_list;
             new_engine->progress = t->progress;
             new_engine->v2 = t->v2;
             new_engine->v2.transforms = transforms; /* assign transforms */
@@ -359,8 +361,10 @@ static void DetectPktInspectEngineCopy(
             if (unlikely(new_engine == NULL)) {
                 exit(EXIT_FAILURE);
             }
-            new_engine->sm_list = new_list;         /* use new list id */
-            new_engine->sm_list_base = sm_list;
+            DEBUG_VALIDATE_BUG_ON(new_list < 0 || new_list > UINT16_MAX);
+            new_engine->sm_list = (uint16_t)new_list; /* use new list id */
+            DEBUG_VALIDATE_BUG_ON(sm_list < 0 || sm_list > UINT16_MAX);
+            new_engine->sm_list_base = (uint16_t)sm_list;
             new_engine->v1 = t->v1;
             new_engine->v1.transforms = transforms; /* assign transforms */
 
@@ -424,7 +428,7 @@ void DetectEngineFrameInspectEngineRegister(DetectEngineCtx *de_ctx, const char
         BUG_ON(1);
     }
 
-    int direction;
+    uint8_t direction;
     if (dir == SIG_FLAG_TOSERVER) {
         direction = 0;
     } else {
@@ -436,8 +440,8 @@ void DetectEngineFrameInspectEngineRegister(DetectEngineCtx *de_ctx, const char
         FatalError(SC_ERR_INITIALIZATION, "failed to register inspect engine %s: %s", name,
                 strerror(errno));
     }
-    new_engine->sm_list = sm_list;
-    new_engine->sm_list_base = sm_list;
+    new_engine->sm_list = (uint16_t)sm_list;
+    new_engine->sm_list_base = (uint16_t)sm_list;
     new_engine->dir = direction;
     new_engine->v1.Callback = Callback;
     new_engine->alproto = alproto;
@@ -469,8 +473,10 @@ static void DetectFrameInspectEngineCopy(DetectEngineCtx *de_ctx, int sm_list, i
             if (unlikely(new_engine == NULL)) {
                 exit(EXIT_FAILURE);
             }
-            new_engine->sm_list = new_list; /* use new list id */
-            new_engine->sm_list_base = sm_list;
+            DEBUG_VALIDATE_BUG_ON(new_list < 0 || new_list > UINT16_MAX);
+            new_engine->sm_list = (uint16_t)new_list; /* use new list id */
+            DEBUG_VALIDATE_BUG_ON(sm_list < 0 || sm_list > UINT16_MAX);
+            new_engine->sm_list_base = (uint16_t)sm_list;
             new_engine->dir = t->dir;
             new_engine->alproto = t->alproto;
             new_engine->type = t->type;
@@ -528,7 +534,8 @@ static void DetectFrameInspectEngineCopyListToDetectCtx(DetectEngineCtx *de_ctx)
  *
  *  If stream inspection is MPM, then prepend it.
  */
-static void AppendStreamInspectEngine(Signature *s, SigMatchData *stream, int direction, uint32_t id)
+static void AppendStreamInspectEngine(
+        Signature *s, SigMatchData *stream, uint8_t direction, uint8_t id)
 {
     bool prepend = false;
 
@@ -695,7 +702,7 @@ int DetectEngineAppInspectionEngine2Signature(DetectEngineCtx *de_ctx, Signature
     }
 
     bool head_is_mpm = false;
-    uint32_t last_id = DE_STATE_FLAG_BASE;
+    uint8_t last_id = DE_STATE_FLAG_BASE;
     const DetectEngineAppInspectionEngine *t = de_ctx->app_inspect_engines;
     while (t != NULL) {
         bool prepend = false;
@@ -937,7 +944,7 @@ static char DetectBufferTypeCompareNameFunc(void *data1, uint16_t len1, void *da
     DetectBufferType *map1 = (DetectBufferType *)data1;
     DetectBufferType *map2 = (DetectBufferType *)data2;
 
-    int r = (strcmp(map1->name, map2->name) == 0);
+    char r = (strcmp(map1->name, map2->name) == 0);
     r &= (memcmp((uint8_t *)&map1->transforms, (uint8_t *)&map2->transforms, sizeof(map2->transforms)) == 0);
     return r;
 }
@@ -1827,8 +1834,9 @@ static int DetectEnginePktInspectionAppend(Signature *s, InspectionBufferPktInsp
         return -1;
 
     e->mpm = s->init_data->mpm_sm_list == list_id;
-    e->sm_list = list_id;
-    e->sm_list_base = list_id;
+    DEBUG_VALIDATE_BUG_ON(list_id < 0 || list_id > UINT16_MAX);
+    e->sm_list = (uint16_t)list_id;
+    e->sm_list_base = (uint16_t)list_id;
     e->v1.Callback = Callback;
     e->smd = data;
 
@@ -2638,9 +2646,8 @@ static int DetectEngineCtxLoadConf(DetectEngineCtx *de_ctx)
             }
             if (max_uniq_toclient_groups_str != NULL) {
                 if (StringParseUint16(&de_ctx->max_uniq_toclient_groups, 10,
-                    strlen(max_uniq_toclient_groups_str),
-                    (const char *)max_uniq_toclient_groups_str) <= 0)
-                {
+                            (uint16_t)strlen(max_uniq_toclient_groups_str),
+                            (const char *)max_uniq_toclient_groups_str) <= 0) {
                     de_ctx->max_uniq_toclient_groups = 20;
 
                     SCLogWarning(SC_ERR_SIZE_PARSE, "parsing '%s' for "
@@ -2655,9 +2662,8 @@ static int DetectEngineCtxLoadConf(DetectEngineCtx *de_ctx)
 
             if (max_uniq_toserver_groups_str != NULL) {
                 if (StringParseUint16(&de_ctx->max_uniq_toserver_groups, 10,
-                    strlen(max_uniq_toserver_groups_str),
-                    (const char *)max_uniq_toserver_groups_str) <= 0)
-                {
+                            (uint16_t)strlen(max_uniq_toserver_groups_str),
+                            (const char *)max_uniq_toserver_groups_str) <= 0) {
                     de_ctx->max_uniq_toserver_groups = 40;
 
                     SCLogWarning(SC_ERR_SIZE_PARSE, "parsing '%s' for "
@@ -3862,9 +3868,8 @@ static int DetectEngineMultiTenantSetupLoadLivedevMappings(const ConfNode *mappi
                 goto bad_mapping;
 
             uint32_t tenant_id = 0;
-            if (StringParseUint32(&tenant_id, 10, strlen(tenant_id_node->val),
-                        tenant_id_node->val) < 0)
-            {
+            if (StringParseUint32(&tenant_id, 10, (uint16_t)strlen(tenant_id_node->val),
+                        tenant_id_node->val) < 0) {
                 SCLogError(SC_ERR_INVALID_ARGUMENT, "tenant-id  "
                         "of %s is invalid", tenant_id_node->val);
                 goto bad_mapping;
@@ -3922,18 +3927,16 @@ static int DetectEngineMultiTenantSetupLoadVlanMappings(const ConfNode *mappings
                 goto bad_mapping;
 
             uint32_t tenant_id = 0;
-            if (StringParseUint32(&tenant_id, 10, strlen(tenant_id_node->val),
-                        tenant_id_node->val) < 0)
-            {
+            if (StringParseUint32(&tenant_id, 10, (uint16_t)strlen(tenant_id_node->val),
+                        tenant_id_node->val) < 0) {
                 SCLogError(SC_ERR_INVALID_ARGUMENT, "tenant-id  "
                         "of %s is invalid", tenant_id_node->val);
                 goto bad_mapping;
             }
 
             uint16_t vlan_id = 0;
-            if (StringParseUint16(&vlan_id, 10, strlen(vlan_id_node->val),
-                        vlan_id_node->val) < 0)
-            {
+            if (StringParseUint16(
+                        &vlan_id, 10, (uint16_t)strlen(vlan_id_node->val), vlan_id_node->val) < 0) {
                 SCLogError(SC_ERR_INVALID_ARGUMENT, "vlan-id  "
                         "of %s is invalid", vlan_id_node->val);
                 goto bad_mapping;
@@ -3944,7 +3947,7 @@ static int DetectEngineMultiTenantSetupLoadVlanMappings(const ConfNode *mappings
                 goto bad_mapping;
             }
 
-            if (DetectEngineTentantRegisterVlanId(tenant_id, (uint32_t)vlan_id) != 0) {
+            if (DetectEngineTentantRegisterVlanId(tenant_id, vlan_id) != 0) {
                 goto error;
             }
             SCLogConfig("vlan %u connected to tenant-id %u", vlan_id, tenant_id);
@@ -4078,9 +4081,8 @@ int DetectEngineMultiTenantSetup(void)
                 }
 
                 uint32_t tenant_id = 0;
-                if (StringParseUint32(&tenant_id, 10, strlen(id_node->val),
-                            id_node->val) < 0)
-                {
+                if (StringParseUint32(
+                            &tenant_id, 10, (uint16_t)strlen(id_node->val), id_node->val) < 0) {
                     SCLogError(SC_ERR_INVALID_ARGUMENT, "tenant_id  "
                             "of %s is invalid", id_node->val);
                     goto bad_tenant;
index 27636618a1ad3e9560e5f1aaf4ad75be89d04efb..5e217b915a442daa1de31ae7a8da7c16cf400dcf 100644 (file)
@@ -320,8 +320,8 @@ error:
  * \retval 0 on Success
  * \retval -1 on Failure
  */
-int DetectFileHashSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str,
-        uint32_t type, int list)
+int DetectFileHashSetup(
+        DetectEngineCtx *de_ctx, Signature *s, const char *str, uint16_t type, int list)
 {
     DetectFileHashData *filehash = NULL;
     SigMatch *sm = NULL;
index 4e8e5ad021f6e4a2961da6a7560cac7dfb4dbeb0..b547e03677f220aa67a34a158b886804be2720d7 100644 (file)
@@ -39,7 +39,7 @@ int LoadHashTable(ROHashTable *, const char *, const char *, int, uint32_t);
 
 int DetectFileHashMatch(DetectEngineThreadCtx *, Flow *, uint8_t,
         File *, const Signature *, const SigMatchCtx *);
-int DetectFileHashSetup(DetectEngineCtx *, Signature *, const char *, uint32_t, int);
+int DetectFileHashSetup(DetectEngineCtx *, Signature *, const char *, uint16_t, int);
 void DetectFileHashFree(DetectEngineCtx *, void *);
 
 #endif /* __UTIL_DETECT_FILE_HASH_H__ */
index d4e095f9d1a97692b630a72b007cc88ee3d1bb36..897d5d3ac3cea87af3f6e499bc779eb1e6dd63a7 100644 (file)
@@ -86,8 +86,8 @@ void DetectFlowRegister (void)
  * \param dflags detect flow flags
  * \param match_cnt number of matches to trigger
  */
-static inline int FlowMatch(const uint32_t pflags, const uint8_t pflowflags,
-    const uint16_t tflags, const uint16_t dflags, const uint8_t match_cnt)
+static inline int FlowMatch(const uint32_t pflags, const uint8_t pflowflags, const uint16_t tflags,
+        const uint16_t dflags, const uint16_t match_cnt)
 {
     uint8_t cnt = 0;
 
@@ -439,8 +439,7 @@ PrefilterPacketFlowMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const void *
     if (!PrefilterPacketHeaderExtraMatch(ctx, p))
         return;
 
-    if (FlowMatch(p->flags, p->flowflags, det_ctx->flags, ctx->v1.u8[0], ctx->v1.u8[1]))
-    {
+    if (FlowMatch(p->flags, p->flowflags, det_ctx->flags, ctx->v1.u16[0], ctx->v1.u16[1])) {
         PrefilterAddSids(&det_ctx->pmq, ctx->sigs_array, ctx->sigs_cnt);
     }
 }
@@ -449,17 +448,15 @@ static void
 PrefilterPacketFlowSet(PrefilterPacketHeaderValue *v, void *smctx)
 {
     const DetectFlowData *fb = smctx;
-    v->u8[0] = fb->flags;
-    v->u8[1] = fb->match_cnt;
+    v->u16[0] = fb->flags;
+    v->u16[1] = fb->match_cnt;
 }
 
 static bool
 PrefilterPacketFlowCompare(PrefilterPacketHeaderValue v, void *smctx)
 {
     const DetectFlowData *fb = smctx;
-    if (v.u8[0] == fb->flags &&
-        v.u8[1] == fb->match_cnt)
-    {
+    if (v.u16[0] == fb->flags && v.u16[1] == fb->match_cnt) {
         return true;
     }
     return false;
index f9af869216ac3463c8625dc9b0d35368522aeac0..ef26057dafcacecf488687ab7a16c613c25cf812 100644 (file)
@@ -28,8 +28,8 @@ typedef struct DetectFlowvarData_ {
     char *name;
     uint32_t idx;
     uint8_t *content;
-    uint8_t content_len;
-    uint8_t flags;
+    uint16_t content_len;
+    uint32_t flags;
 } DetectFlowvarData;
 
 /* prototypes */
index bdb33974279ad5fc958489574595383211e80022..fd0996832000cdaae0d91b3c25e96061aee8516e 100644 (file)
@@ -101,13 +101,13 @@ static int InspectFtpRequest(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det
  *
  * \retval 1 if ftpbounce detected, 0 if not
  */
-static int DetectFtpbounceMatchArgs(uint8_t *payload, uint16_t payload_len,
-                             uint32_t ip_orig, uint16_t offset)
+static int DetectFtpbounceMatchArgs(
+        uint8_t *payload, uint32_t payload_len, uint32_t ip_orig, uint32_t offset)
 {
     SCEnter();
     SCLogDebug("Checking ftpbounce condition");
     char *c = NULL;
-    uint16_t i = 0;
+    uint32_t i = 0;
     int octet = 0;
     int octet_ascii_len = 0;
     int noctet = 0;
index 5e4a41724b659cd0b29cc26afb4a12afd53e440d..e0682e05b195217ed74280e4a05d4e1ce9cc377c 100644 (file)
@@ -266,14 +266,14 @@ static int DetectHTTP2frametypeMatch(DetectEngineThreadCtx *det_ctx,
 static int DetectHTTP2FuncParseFrameType(const char *str, uint8_t *ft)
 {
     // first parse numeric value
-    if (ByteExtractStringUint8(ft, 10, strlen(str), str) >= 0) {
+    if (ByteExtractStringUint8(ft, 10, (uint16_t)strlen(str), str) >= 0) {
         return 1;
     }
 
     // it it failed so far, parse string value from enumeration
     int r = rs_http2_parse_frametype(str);
-    if (r >= 0) {
-        *ft = r;
+    if (r >= 0 && r <= UINT8_MAX) {
+        *ft = (uint8_t)r;
         return 1;
     }
 
@@ -352,7 +352,7 @@ static int DetectHTTP2errorcodeMatch(DetectEngineThreadCtx *det_ctx,
 static int DetectHTTP2FuncParseErrorCode(const char *str, uint32_t *ec)
 {
     // first parse numeric value
-    if (ByteExtractStringUint32(ec, 10, strlen(str), str) >= 0) {
+    if (ByteExtractStringUint32(ec, 10, (uint16_t)strlen(str), str) >= 0) {
         return 1;
     }
 
@@ -433,7 +433,7 @@ static int DetectHTTP2priorityMatch(DetectEngineThreadCtx *det_ctx,
     int value = rs_http2_tx_get_next_priority(txv, flags, nb);
     const DetectU8Data *du8 = (const DetectU8Data *)ctx;
     while (value >= 0) {
-        if (DetectU8Match(value, du8)) {
+        if (DetectU8Match((uint8_t)value, du8)) {
             return 1;
         }
         nb++;
index 8005560e838c9ace0c64cba347c3bda0276cfb05..bdf0ef5a692b84a6e0c29083e8cd5a6e4ed464b3 100644 (file)
@@ -122,7 +122,7 @@ static int DetectIdMatch (DetectEngineThreadCtx *det_ctx, Packet *p,
  */
 static DetectIdData *DetectIdParse (const char *idstr)
 {
-    uint32_t temp;
+    uint16_t temp;
     DetectIdData *id_d = NULL;
     int ret = 0, res = 0;
     size_t pcre2len;
@@ -154,8 +154,7 @@ static DetectIdData *DetectIdParse (const char *idstr)
     }
 
     /* ok, fill the id data */
-    if (StringParseU32RangeCheck(&temp, 10, 0, (const char *)tmp_str,
-                                 DETECT_IPID_MIN, DETECT_IPID_MAX) < 0) {
+    if (StringParseUint16(&temp, 10, 0, (const char *)tmp_str) < 0) {
         SCLogError(SC_ERR_INVALID_VALUE, "invalid id option '%s'", tmp_str);
         return NULL;
     }
index 09cbfe8790ba7665768298e1fa12ed31965f1f79..f8174194de7b9bc408bb95d3003e73d042280a30 100644 (file)
@@ -241,7 +241,7 @@ static int DetectIPProtoSetup(DetectEngineCtx *de_ctx, Signature *s, const char
                 goto error;
             }
             if (!lt_set && !not_set) {
-                s->proto.proto[data->proto / 8] = 0xfe << (data->proto % 8);
+                s->proto.proto[data->proto / 8] = (uint8_t)(0xfe << (data->proto % 8));
                 for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
                     s->proto.proto[i] = 0xff;
                 }
@@ -319,7 +319,7 @@ static int DetectIPProtoSetup(DetectEngineCtx *de_ctx, Signature *s, const char
                 for (i = 0; i < (data->proto / 8); i++) {
                     s->proto.proto[i] = 0xff;
                 }
-                s->proto.proto[data->proto / 8] = ~(0xff << (data->proto % 8));
+                s->proto.proto[data->proto / 8] = (uint8_t)(~(0xff << (data->proto % 8)));
             } else if (gt_set && !not_set) {
                 SigMatch *temp_sm = s->init_data->smlists[DETECT_SM_LIST_MATCH];
                 while (temp_sm != NULL) {
@@ -394,7 +394,7 @@ static int DetectIPProtoSetup(DetectEngineCtx *de_ctx, Signature *s, const char
                 for (i = 0; i < (data->proto / 8); i++) {
                     s->proto.proto[i] = 0xff;
                 }
-                s->proto.proto[data->proto / 8] = ~(1 << (data->proto % 8));
+                s->proto.proto[data->proto / 8] = (uint8_t)(~(1 << (data->proto % 8)));
                 for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
                     s->proto.proto[i] = 0xff;
                 }
index eec83ab30dd3382243a04cf292914508e8aabe4b..c311c1a15517d295fde5fbf3d4b520e14a77e849 100644 (file)
@@ -85,7 +85,8 @@ void DetectMetadataHashFree(DetectEngineCtx *de_ctx)
 
 static const char *DetectMedatataHashAdd(DetectEngineCtx *de_ctx, const char *string)
 {
-    const char * hstring = (char *)HashTableLookup(de_ctx->metadata_table, (void *)string, strlen(string));
+    const char *hstring = (char *)HashTableLookup(
+            de_ctx->metadata_table, (void *)string, (uint16_t)strlen(string));
     if (hstring) {
         return hstring;
     }
@@ -95,8 +96,9 @@ static const char *DetectMedatataHashAdd(DetectEngineCtx *de_ctx, const char *st
         return NULL;
     }
 
-    if (HashTableAdd(de_ctx->metadata_table, (void *)astring, strlen(astring)) == 0) {
-        return (char *)HashTableLookup(de_ctx->metadata_table, (void *)astring, strlen(astring));
+    if (HashTableAdd(de_ctx->metadata_table, (void *)astring, (uint16_t)strlen(astring)) == 0) {
+        return (char *)HashTableLookup(
+                de_ctx->metadata_table, (void *)astring, (uint16_t)strlen(astring));
     } else {
         SCFree((void *)astring);
     }
index d7df02b367557a58194913ea2c8c526727065188..8a15defabfdcf7615928e65a8d29db879ac2af07 100644 (file)
@@ -181,7 +181,7 @@ int DetectPcrePayloadMatch(DetectEngineThreadCtx *det_ctx, const Signature *s,
     SCEnter();
     int ret = 0;
     const uint8_t *ptr = NULL;
-    uint16_t len = 0;
+    uint32_t len = 0;
     PCRE2_SIZE capture_len = 0;
 
     DetectPcreData *pe = (DetectPcreData *)smd->ctx;
@@ -273,20 +273,17 @@ int DetectPcrePayloadMatch(DetectEngineThreadCtx *det_ctx, const Signature *s,
                         memcpy(str_ptr2, pcre2_str_ptr2, capture_len);
                         pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
 
-                        (void)DetectVarStoreMatchKeyValue(det_ctx,
-                                (uint8_t *)str_ptr, key_len,
-                                (uint8_t *)str_ptr2, capture_len,
+                        (void)DetectVarStoreMatchKeyValue(det_ctx, (uint8_t *)str_ptr, key_len,
+                                (uint8_t *)str_ptr2, (uint16_t)capture_len,
                                 DETECT_VAR_TYPE_PKT_POSTMATCH);
 
                     } else if (pe->captypes[x] == VAR_TYPE_PKT_VAR) {
-                        (void)DetectVarStoreMatch(det_ctx, pe->capids[x],
-                                (uint8_t *)str_ptr, capture_len,
-                                DETECT_VAR_TYPE_PKT_POSTMATCH);
+                        (void)DetectVarStoreMatch(det_ctx, pe->capids[x], (uint8_t *)str_ptr,
+                                (uint16_t)capture_len, DETECT_VAR_TYPE_PKT_POSTMATCH);
 
                     } else if (pe->captypes[x] == VAR_TYPE_FLOW_VAR && f != NULL) {
-                        (void)DetectVarStoreMatch(det_ctx, pe->capids[x],
-                                (uint8_t *)str_ptr, capture_len,
-                                DETECT_VAR_TYPE_FLOW_POSTMATCH);
+                        (void)DetectVarStoreMatch(det_ctx, pe->capids[x], (uint8_t *)str_ptr,
+                                (uint16_t)capture_len, DETECT_VAR_TYPE_FLOW_POSTMATCH);
                     } else {
                         BUG_ON(1); // Impossible captype
                         SCFree(str_ptr);
index e6e5211dd6eaeba029be4b8ca5a9328e3a2afabe..ecd0243904a70433ba934d4f98547ea40b6af856 100644 (file)
@@ -26,7 +26,7 @@
 
 typedef struct DetectPktvarData_ {
     uint32_t id;
-    uint8_t content_len;
+    uint16_t content_len;
     uint8_t flags;
     uint8_t *content;
 } DetectPktvarData;
index 98fe82d30b773c422142a6bcdc67fda1ab37160e..d1e9eda845c80e54112b49ed2224771ead3a8283 100644 (file)
@@ -200,7 +200,7 @@ static DetectSshVersionData *DetectSshVersionParse (DetectEngineCtx *de_ctx, con
             pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
             goto error;
         }
-        ssh->len = strlen((char *) ssh->ver);
+        ssh->len = (uint16_t)strlen((char *)ssh->ver);
         pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
 
         SCLogDebug("will look for ssh %s", ssh->ver);
index 653b8c3f3040238f674e3b66efee77f95e3835b9..da6708fe72bd17e319c19f5a1937e3e943a3acf5 100644 (file)
@@ -193,7 +193,7 @@ static DetectSshSoftwareVersionData *DetectSshSoftwareVersionParse (DetectEngine
         }
         pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
 
-        ssh->len = strlen((char *)ssh->software_ver);
+        ssh->len = (uint16_t)strlen((char *)ssh->software_ver);
 
         SCLogDebug("will look for ssh %s", ssh->software_ver);
     }
index efcd09dee5ef2efe1513cf04c7dd38e1e0350be9..6eb0af27e6e6171eb68dae50414b41d2caaea89a 100644 (file)
@@ -177,7 +177,7 @@ static int DetectSslVersionMatch(DetectEngineThreadCtx *det_ctx,
 struct SSLVersionKeywords {
     const char *word;
     int index;
-    int value;
+    uint16_t value;
 };
 
 struct SSLVersionKeywords ssl_version_keywords[TLS_SIZE] = {
index 6774f49549d59016ed737c1333c093459c5e5bea..6db80e4096d915f94408a4e0d8143a512b53d0da 100644 (file)
@@ -66,7 +66,7 @@ typedef struct DetectTagData_ {
     uint8_t type;          /**< tag type */
     uint8_t direction;     /**< host direction */
     uint32_t count;        /**< count */
-    uint32_t metric;       /**< metric */
+    uint8_t metric;        /**< metric */
 } DetectTagData;
 
 /** This is the installed data at the session/global or host table */
index 526561f2f9924a8410dd00b735ff97f77d4e1fc3..70717aac73328cf45322c25f3bb36213a3568a2b 100644 (file)
@@ -86,7 +86,9 @@ static bool BufferUrlDecode(const uint8_t *input, const uint32_t input_len, uint
             if (i + 2 < input_len) {
                 if ((isxdigit(input[i+1])) && (isxdigit(input[i+2]))) {
                     // Decode %HH encoding.
-                    *oi = (input[i+1] >= 'A' ? ((input[i+1] & 0xdf) - 'A') + 10 : (input[i+1] - '0')) << 4;
+                    *oi = (uint8_t)((input[i + 1] >= 'A' ? ((input[i + 1] & 0xdf) - 'A') + 10
+                                                         : (input[i + 1] - '0'))
+                                    << 4);
                     *oi |= (input[i+2] >= 'A' ? ((input[i+2] & 0xdf) - 'A') + 10 : (input[i+2] - '0'));
                     oi++;
                     // one more increment before looping
index 7fbae5239b84610bcd95e5dd3aa5706557ecc0a1..7fbf7fb3cda05a3bb1314f322ea16b33ccac0e30 100644 (file)
@@ -96,7 +96,7 @@ static int DetectTransformXorSetup(DetectEngineCtx *de_ctx, Signature *s, const
         DetectTransformXorFree(de_ctx, pxd);
         SCReturnInt(-1);
     }
-    pxd->length = keylen / 2;
+    pxd->length = (uint8_t)(keylen / 2);
     pxd->key = SCMalloc(keylen / 2);
     if (pxd->key == NULL) {
         SCLogError(SC_ERR_MEM_ALLOC, "memory allocation failed");
@@ -105,9 +105,9 @@ static int DetectTransformXorSetup(DetectEngineCtx *de_ctx, Signature *s, const
     }
     for (size_t i = 0; i < keylen / 2; i++) {
         if ((isxdigit(optstr[2 * i])) && (isxdigit(optstr[2 * i + 1]))) {
-            pxd->key[i] = (optstr[2 * i] >= 'A' ? ((optstr[2 * i] & 0xdf) - 'A') + 10
-                                                : (optstr[2 * i] - '0'))
-                          << 4;
+            pxd->key[i] = (uint8_t)((optstr[2 * i] >= 'A' ? ((optstr[2 * i] & 0xdf) - 'A') + 10
+                                                          : (optstr[2 * i] - '0'))
+                                    << 4);
             pxd->key[i] |= (optstr[2 * i + 1] >= 'A' ? ((optstr[2 * i + 1] & 0xdf) - 'A') + 10
                                                      : (optstr[2 * i + 1] - '0'));
         } else {
index ba44ef66ede53a5578ad89113bb96ea8677f87fa..202fbb05850d6a6abd838eeae4ffdd068881fb86 100644 (file)
@@ -175,7 +175,7 @@ static DetectUrilenData *DetectUrilenParse (const char *urilenstr)
     }
 
     /** set the first urilen value */
-    if (StringParseUint16(&urilend->urilen1,10,strlen(arg2),arg2) <= 0){
+    if (StringParseUint16(&urilend->urilen1, 10, (uint16_t)strlen(arg2), arg2) <= 0) {
         SCLogError(SC_ERR_INVALID_ARGUMENT,"Invalid size :\"%s\"",arg2);
         goto error;
     }
@@ -188,8 +188,7 @@ static DetectUrilenData *DetectUrilenParse (const char *urilenstr)
             goto error;
         }
 
-        if(StringParseUint16(&urilend->urilen2,10,strlen(arg4),arg4) <= 0)
-        {
+        if (StringParseUint16(&urilend->urilen2, 10, (uint16_t)strlen(arg4), arg4) <= 0) {
             SCLogError(SC_ERR_INVALID_ARGUMENT,"Invalid size :\"%s\"",arg4);
             goto error;
         }
index fdc2bd7c5b4abe4fd848cb61231ce0a49d0eb1c3..71ee309bb0514724f174aad39b2d5f2a65f12faf 100644 (file)
@@ -369,15 +369,14 @@ static inline void DetectPrefilterMergeSort(DetectEngineCtx *de_ctx,
 /** \internal
  *  \brief build non-prefilter list based on the rule group list we've set.
  */
-static inline void
-DetectPrefilterBuildNonPrefilterList(DetectEngineThreadCtx *det_ctx,
-        const SignatureMask mask, const uint8_t alproto)
+static inline void DetectPrefilterBuildNonPrefilterList(
+        DetectEngineThreadCtx *det_ctx, const SignatureMask mask, const AppProto alproto)
 {
     for (uint32_t x = 0; x < det_ctx->non_pf_store_cnt; x++) {
         /* only if the mask matches this rule can possibly match,
          * so build the non_mpm array only for match candidates */
         const SignatureMask rule_mask = det_ctx->non_pf_store_ptr[x].mask;
-        const uint8_t rule_alproto = det_ctx->non_pf_store_ptr[x].alproto;
+        const AppProto rule_alproto = det_ctx->non_pf_store_ptr[x].alproto;
         if ((rule_mask & mask) == rule_mask &&
                 (rule_alproto == 0 || AppProtoEquals(rule_alproto, alproto))) {
             det_ctx->non_pf_id_array[det_ctx->non_pf_id_cnt++] = det_ctx->non_pf_store_ptr[x].id;
@@ -1070,7 +1069,7 @@ static bool DetectRunTxInspectRule(ThreadVars *tv,
     const int direction = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
     uint32_t inspect_flags = stored_flags ? *stored_flags : 0;
     int total_matches = 0;
-    int file_no_match = 0;
+    uint16_t file_no_match = 0;
     bool retval = false;
     bool mpm_before_progress = false;   // is mpm engine before progress?
     bool mpm_in_progress = false;       // is mpm engine in a buffer we will revisit?
@@ -1150,7 +1149,8 @@ static bool DetectRunTxInspectRule(ThreadVars *tv,
                 TRACE_SID_TXS(s->id, tx, "engine %p match %d", engine, match);
                 if (engine->stream) {
                     can->stream_stored = true;
-                    can->stream_result = match;
+                    // TODO change Callback prototype ?
+                    can->stream_result = (uint8_t)match;
                     TRACE_SID_TXS(s->id, tx, "stream ran, store result %d for next tx (if any)", match);
                 }
             }
index 37f40b9d6b42de23ec70dd60664af40a7ea3a3a3..b01c6edf91f475c849eb4f34561b7e943061b45d 100644 (file)
@@ -843,7 +843,7 @@ typedef struct DetectEngineCtx_ {
     DetectEngineIPOnlyCtx io_ctx;
     ThresholdCtx ths_ctx;
 
-    uint16_t mpm_matcher; /**< mpm matcher this ctx uses */
+    uint8_t mpm_matcher;  /**< mpm matcher this ctx uses */
     uint16_t spm_matcher; /**< spm matcher this ctx uses */
 
     /* spm thread context prototype, built as spm matchers are constructed and
@@ -1021,7 +1021,7 @@ typedef struct HttpReassembledBody_ {
 typedef struct SignatureNonPrefilterStore_ {
     SigIntId id;
     SignatureMask mask;
-    uint8_t alproto;
+    AppProto alproto;
 } SignatureNonPrefilterStore;
 
 /** array of TX inspect rule candidates */