From: Philippe Antoine Date: Fri, 14 Jan 2022 09:05:54 +0000 (+0100) Subject: util: fix int warnings X-Git-Tag: suricata-7.0.0-beta1~826 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3ab126394f4f74778fc20a1335ed2a22a486723;p=thirdparty%2Fsuricata.git util: fix int warnings Ticket: 4516 --- diff --git a/src/decode-tcp.h b/src/decode-tcp.h index 4bcb7b22e5..01c3903261 100644 --- a/src/decode-tcp.h +++ b/src/decode-tcp.h @@ -109,7 +109,7 @@ #define TCP_GET_OFFSET(p) TCP_GET_RAW_OFFSET((p)->tcph) #define TCP_GET_X2(p) TCP_GET_RAW_X2((p)->tcph) -#define TCP_GET_HLEN(p) (TCP_GET_OFFSET((p)) << 2) +#define TCP_GET_HLEN(p) ((uint8_t)(TCP_GET_OFFSET((p)) << 2)) #define TCP_GET_SRC_PORT(p) TCP_GET_RAW_SRC_PORT((p)->tcph) #define TCP_GET_DST_PORT(p) TCP_GET_RAW_DST_PORT((p)->tcph) #define TCP_GET_SEQ(p) TCP_GET_RAW_SEQ((p)->tcph) diff --git a/src/suricata.h b/src/suricata.h index 81d63716e0..5d15424809 100644 --- a/src/suricata.h +++ b/src/suricata.h @@ -175,8 +175,8 @@ extern uint16_t g_vlan_mask; extern bool g_disable_hashing; #include -#define u8_tolower(c) tolower((uint8_t)(c)) -#define u8_toupper(c) toupper((uint8_t)(c)) +#define u8_tolower(c) ((uint8_t)tolower((uint8_t)(c))) +#define u8_toupper(c) ((uint8_t)toupper((uint8_t)(c))) void EngineStop(void); void EngineDone(void); diff --git a/src/util-affinity.c b/src/util-affinity.c index 3a9c8f08a1..04b96321ce 100644 --- a/src/util-affinity.c +++ b/src/util-affinity.c @@ -296,7 +296,7 @@ void AffinitySetupLoadFromConfig() */ int AffinityGetNextCPU(ThreadsAffinityType *taf) { - int ncpu = 0; + uint16_t ncpu = 0; #if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun int iter = 0; SCMutexLock(&taf->taf_mutex); diff --git a/src/util-base64.c b/src/util-base64.c index bea92d52bb..182ed8285f 100644 --- a/src/util-base64.c +++ b/src/util-base64.c @@ -116,7 +116,7 @@ uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len, /* For each alpha-numeric letter in the source array, find the numeric * value */ - b64[bbidx++] = (val > 0 ? val : 0); + b64[bbidx++] = (val > 0 ? (uint8_t)val : 0); /* Decode every 4 base64 bytes into 3 ascii bytes */ if (bbidx == B64_BLOCK) { diff --git a/src/util-cpu.c b/src/util-cpu.c index 068e8dbe3b..39f0db582b 100644 --- a/src/util-cpu.c +++ b/src/util-cpu.c @@ -121,7 +121,7 @@ uint16_t UtilCpuGetNumProcessorsOnline(void) return UINT16_MAX; } - return nprocs; + return (uint16_t)nprocs; #elif OS_WIN32 return UtilCpuGetNumProcessorsConfigured(); #else diff --git a/src/util-debug.h b/src/util-debug.h index 24915471ed..b3e15cdedb 100644 --- a/src/util-debug.h +++ b/src/util-debug.h @@ -118,7 +118,7 @@ typedef struct SCLogOPIfaceCtx_ { SCLogOPIface iface; int16_t use_color; - int16_t type; + SCLogOPType type; /* the output file to be used if the interface is SC_LOG_IFACE_FILE */ const char *file; diff --git a/src/util-fix_checksum.c b/src/util-fix_checksum.c index ec2280789f..4fc60004ac 100644 --- a/src/util-fix_checksum.c +++ b/src/util-fix_checksum.c @@ -54,7 +54,6 @@ FixChecksum(uint16_t sum, uint16_t old, uint16_t new) l = sum + old - new; l = (l >> 16) + (l & 65535); - l = l & 65535; - return l; + return (uint16_t)(l & 65535); } diff --git a/src/util-host-os-info.c b/src/util-host-os-info.c index 622907890b..b8f3fa2185 100644 --- a/src/util-host-os-info.c +++ b/src/util-host-os-info.c @@ -126,7 +126,7 @@ int SCHInfoAddHostOSInfo(const char *host_os, const char *host_os_ip_range, int struct in_addr *ipv4_addr = NULL; struct in6_addr *ipv6_addr = NULL; char *netmask_str = NULL; - int netmask_value = 0; + uint8_t netmask_value = 0; int *user_data = NULL; bool recursive = false; @@ -185,7 +185,8 @@ int SCHInfoAddHostOSInfo(const char *host_os, const char *host_os_ip_range, int SCRadixAddKeyIPV4((uint8_t *)ipv4_addr, sc_hinfo_tree, (void *)user_data); } else { - if (StringParseI32RangeCheck(&netmask_value, 10, 0, (const char *)netmask_str, 0, 32) < 0) { + if (StringParseU8RangeCheck(&netmask_value, 10, 0, (const char *)netmask_str, 0, 32) < + 0) { SCLogError(SC_ERR_INVALID_IP_NETBLOCK, "Invalid IPV4 Netblock"); SCHInfoFreeUserDataOSPolicy(user_data); SCFree(ipv4_addr); @@ -210,7 +211,8 @@ int SCHInfoAddHostOSInfo(const char *host_os, const char *host_os_ip_range, int SCRadixAddKeyIPV6((uint8_t *)ipv6_addr, sc_hinfo_tree, (void *)user_data); } else { - if (StringParseI32RangeCheck(&netmask_value, 10, 0, (const char *)netmask_str, 0, 128) < 0) { + if (StringParseU8RangeCheck(&netmask_value, 10, 0, (const char *)netmask_str, 0, 128) < + 0) { SCLogError(SC_ERR_INVALID_IP_NETBLOCK, "Invalid IPV6 Netblock"); SCHInfoFreeUserDataOSPolicy(user_data); SCFree(ipv6_addr); diff --git a/src/util-ioctl.c b/src/util-ioctl.c index c86a1fb05a..83ae688f63 100644 --- a/src/util-ioctl.c +++ b/src/util-ioctl.c @@ -206,7 +206,7 @@ int SetIfaceFlags(const char *ifname, int flags) ifr.ifr_flags = flags & 0xffff; ifr.ifr_flagshigh = flags >> 16; #else - ifr.ifr_flags = flags; + ifr.ifr_flags = (uint16_t)flags; #endif if (ioctl(fd, SIOCSIFFLAGS, &ifr) == -1) { diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index 58bccd5335..90626aad51 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -401,7 +401,7 @@ SCLogOpenFileFp(const char *path, const char *append_setting, uint32_t mode) filename, strerror(errno)); } else { if (mode != 0) { - int r = chmod(filename, mode); + int r = chmod(filename, (mode_t)mode); if (r < 0) { SCLogWarning(SC_WARN_CHMOD, "Could not chmod %s to %o: %s", filename, mode, strerror(errno)); @@ -494,9 +494,7 @@ SCConfLogOpenGeneric(ConfNode *conf, const char *filemode = ConfNodeLookupChildValue(conf, "filemode"); uint32_t mode = 0; - if (filemode != NULL && - StringParseUint32(&mode, 8, strlen(filemode), - filemode) > 0) { + if (filemode != NULL && StringParseUint32(&mode, 8, (uint16_t)strlen(filemode), filemode) > 0) { log_ctx->filemode = mode; } diff --git a/src/util-mpm-ac-bs.c b/src/util-mpm-ac-bs.c index 2a56aa1046..a507ec6778 100644 --- a/src/util-mpm-ac-bs.c +++ b/src/util-mpm-ac-bs.c @@ -59,6 +59,7 @@ #include "util-unittest-helper.h" #include "util-memcmp.h" #include "util-memcpy.h" +#include "util-validate.h" void SCACBSInitCtx(MpmCtx *); void SCACBSInitThreadCtx(MpmCtx *, MpmThreadCtx *); @@ -495,7 +496,8 @@ static inline void SCACBSCreateDeltaTable(MpmCtx *mpm_ctx) memset(&q, 0, sizeof(StateQueue)); for (ascii_code = 0; ascii_code < 256; ascii_code++) { - SC_AC_BS_STATE_TYPE_U16 temp_state = ctx->goto_table[0][ascii_code]; + DEBUG_VALIDATE_BUG_ON(ctx->goto_table[0][ascii_code] > UINT16_MAX); + SC_AC_BS_STATE_TYPE_U16 temp_state = (uint16_t)ctx->goto_table[0][ascii_code]; ctx->state_table_u16[0][ascii_code] = temp_state; if (temp_state != 0) SCACBSEnqueue(&q, temp_state); @@ -508,7 +510,8 @@ static inline void SCACBSCreateDeltaTable(MpmCtx *mpm_ctx) int32_t temp_state = ctx->goto_table[r_state][ascii_code]; if (temp_state != SC_AC_BS_FAIL) { SCACBSEnqueue(&q, temp_state); - ctx->state_table_u16[r_state][ascii_code] = temp_state; + DEBUG_VALIDATE_BUG_ON(temp_state > UINT16_MAX); + ctx->state_table_u16[r_state][ascii_code] = (uint16_t)temp_state; } else { ctx->state_table_u16[r_state][ascii_code] = ctx->state_table_u16[ctx->failure_table[r_state]][ascii_code]; diff --git a/src/util-mpm-ac-ks.c b/src/util-mpm-ac-ks.c index deb574f0aa..3f7153d17a 100644 --- a/src/util-mpm-ac-ks.c +++ b/src/util-mpm-ac-ks.c @@ -78,6 +78,7 @@ #include "util-unittest-helper.h" #include "util-memcmp.h" #include "util-memcpy.h" +#include "util-validate.h" #include "util-mpm-ac-ks.h" #if __BYTE_ORDER == __LITTLE_ENDIAN @@ -198,7 +199,8 @@ static void SCACTileInitTranslateTable(SCACTileCtx *ctx) } if (ctx->alpha_hist[i]) { ctx->alphabet_size++; - ctx->translate_table[i] = ctx->alphabet_size; + DEBUG_VALIDATE_BUG_ON(ctx->alphabet_size > UINT8_MAX); + ctx->translate_table[i] = (uint8_t)ctx->alphabet_size; } else ctx->translate_table[i] = 0; } @@ -554,7 +556,8 @@ static void SCACTileSetState1Byte(SCACTileCtx *ctx, int state, int aa, int next_state, int outputs) { uint8_t *state_table = (uint8_t*)ctx->state_table; - uint8_t encoded_next_state = next_state; + DEBUG_VALIDATE_BUG_ON(next_state < 0 || next_state > UINT8_MAX); + uint8_t encoded_next_state = (uint8_t)next_state; if (next_state == SC_AC_TILE_FAIL) { FatalError(SC_ERR_FATAL, "Error FAIL state in output"); @@ -573,7 +576,8 @@ static void SCACTileSetState2Bytes(SCACTileCtx *ctx, int state, int aa, int next_state, int outputs) { uint16_t *state_table = (uint16_t*)ctx->state_table; - uint16_t encoded_next_state = next_state; + DEBUG_VALIDATE_BUG_ON(next_state < 0 || next_state > UINT16_MAX); + uint16_t encoded_next_state = (uint16_t)next_state; if (next_state == SC_AC_TILE_FAIL) { FatalError(SC_ERR_FATAL, "Error FAIL state in output"); @@ -929,7 +933,7 @@ int SCACTilePreparePatterns(MpmCtx *mpm_ctx) /* Now make the copies of the no-case strings. */ for (i = 0; i < mpm_ctx->pattern_cnt; i++) { if (!(ctx->parray[i]->flags & MPM_PATTERN_FLAG_NOCASE)) { - uint32_t len = ctx->parray[i]->len; + uint16_t len = ctx->parray[i]->len; uint32_t space = ((len + 7) / 8) * 8; memcpy(string_space, ctx->parray[i]->original_pat, len); ctx->pattern_list[i].cs = string_space; @@ -1248,7 +1252,8 @@ uint32_t SCACTileSearchLarge(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thr for (i = 0; i < buflen; i++) { state = state_table_u32[state & 0x00FFFFFF][xlate[buf[i]]]; if (SCHECK(state)) { - matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); + DEBUG_VALIDATE_BUG_ON(state < 0 || state > UINT16_MAX); + matches = CheckMatch(ctx, pmq, buf, buflen, (uint16_t)state, i, matches, mpm_bitarray); } } /* for (i = 0; i < buflen; i++) */ diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 62415321a0..84129d4b26 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -59,6 +59,7 @@ #include "util-memcmp.h" #include "util-mpm-ac.h" #include "util-memcpy.h" +#include "util-validate.h" void SCACInitCtx(MpmCtx *); void SCACInitThreadCtx(MpmCtx *, MpmThreadCtx *); @@ -578,7 +579,8 @@ static inline void SCACCreateDeltaTable(MpmCtx *mpm_ctx) memset(&q, 0, sizeof(StateQueue)); for (ascii_code = 0; ascii_code < 256; ascii_code++) { - SC_AC_STATE_TYPE_U16 temp_state = ctx->goto_table[0][ascii_code]; + DEBUG_VALIDATE_BUG_ON(ctx->goto_table[0][ascii_code] > UINT16_MAX); + SC_AC_STATE_TYPE_U16 temp_state = (uint16_t)ctx->goto_table[0][ascii_code]; ctx->state_table_u16[0][ascii_code] = temp_state; if (temp_state != 0) SCACEnqueue(&q, temp_state); @@ -591,7 +593,8 @@ static inline void SCACCreateDeltaTable(MpmCtx *mpm_ctx) int32_t temp_state = ctx->goto_table[r_state][ascii_code]; if (temp_state != SC_AC_FAIL) { SCACEnqueue(&q, temp_state); - ctx->state_table_u16[r_state][ascii_code] = temp_state; + DEBUG_VALIDATE_BUG_ON(temp_state > UINT16_MAX); + ctx->state_table_u16[r_state][ascii_code] = (uint16_t)temp_state; } else { ctx->state_table_u16[r_state][ascii_code] = ctx->state_table_u16[ctx->failure_table[r_state]][ascii_code]; diff --git a/src/util-mpm.c b/src/util-mpm.c index 851df27c49..2cd1b9a690 100644 --- a/src/util-mpm.c +++ b/src/util-mpm.c @@ -46,7 +46,7 @@ #endif MpmTableElmt mpm_table[MPM_TABLE_SIZE]; -uint16_t mpm_default_matcher; +uint8_t mpm_default_matcher; /** * \brief Register a new Mpm Context. @@ -197,7 +197,7 @@ void MpmInitThreadCtx(MpmThreadCtx *mpm_thread_ctx, uint16_t matcher) mpm_table[matcher].InitThreadCtx(NULL, mpm_thread_ctx); } -void MpmInitCtx (MpmCtx *mpm_ctx, uint16_t matcher) +void MpmInitCtx(MpmCtx *mpm_ctx, uint8_t matcher) { mpm_ctx->mpm_type = matcher; mpm_table[matcher].InitCtx(mpm_ctx); diff --git a/src/util-mpm.h b/src/util-mpm.h index e6669f614e..f7a0c682cf 100644 --- a/src/util-mpm.h +++ b/src/util-mpm.h @@ -170,7 +170,7 @@ typedef struct MpmTableElmt_ { } MpmTableElmt; extern MpmTableElmt mpm_table[MPM_TABLE_SIZE]; -extern uint16_t mpm_default_matcher; +extern uint8_t mpm_default_matcher; struct DetectEngineCtx_; @@ -188,7 +188,7 @@ void PmqFree(PrefilterRuleStore *); void MpmTableSetup(void); void MpmRegisterTests(void); -void MpmInitCtx(MpmCtx *mpm_ctx, uint16_t matcher); +void MpmInitCtx(MpmCtx *mpm_ctx, uint8_t matcher); void MpmInitThreadCtx(MpmThreadCtx *mpm_thread_ctx, uint16_t); int MpmAddPatternCS(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen, diff --git a/src/util-proto-name.c b/src/util-proto-name.c index b0f52fed58..e63d964d5b 100644 --- a/src/util-proto-name.c +++ b/src/util-proto-name.c @@ -380,7 +380,7 @@ static char ProtoNameHashCompareFunc(void *data1, uint16_t datalen1, void *data2 return len1 == len2 && memcmp(p1->name, p2->name, len1) == 0; } -static void ProtoNameAddEntry(const char *proto_name, const int proto_number) +static void ProtoNameAddEntry(const char *proto_name, const uint8_t proto_number) { ProtoNameHashEntry *proto_ent = SCCalloc(1, sizeof(ProtoNameHashEntry)); if (!proto_ent) { @@ -423,15 +423,15 @@ void SCProtoNameInit(void) FatalError(SC_ERR_HASH_TABLE_INIT, "Unable to initialize protocol name/number table"); } - for (uint32_t i = 0; i < ARRAY_SIZE(known_proto); i++) { + for (uint16_t i = 0; i < ARRAY_SIZE(known_proto); i++) { if (known_proto[i]) { - ProtoNameAddEntry(known_proto[i], i); + ProtoNameAddEntry(known_proto[i], (uint8_t)i); } } - for (uint32_t i = 0; i < ARRAY_SIZE(proto_aliases); i++) { + for (uint16_t i = 0; i < ARRAY_SIZE(proto_aliases); i++) { if (proto_aliases[i]) { - ProtoNameAddEntry(proto_aliases[i], i); + ProtoNameAddEntry(proto_aliases[i], (uint8_t)i); } } } diff --git a/src/util-radix-tree.c b/src/util-radix-tree.c index 6a567935b8..9d2074bc65 100644 --- a/src/util-radix-tree.c +++ b/src/util-radix-tree.c @@ -488,8 +488,8 @@ void SCRadixReleaseRadixTree(SCRadixTree *tree) * * \retval node Pointer to the newly created node */ -static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen, - SCRadixTree *tree, void *user, uint8_t netmask) +static SCRadixNode *SCRadixAddKey( + uint8_t *key_stream, uint8_t key_bitlen, SCRadixTree *tree, void *user, uint8_t netmask) { SCRadixNode *node = NULL; SCRadixNode *new_node = NULL; @@ -501,11 +501,11 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen, uint8_t *stream = NULL; uint8_t bitlen = 0; - int check_bit = 0; - int differ_bit = 0; + uint16_t check_bit = 0; + uint16_t differ_bit = 0; - int i = 0; - int j = 0; + uint16_t i = 0; + uint16_t j = 0; int temp = 0; if (tree == NULL) { @@ -683,14 +683,14 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen, node->netmasks[node->netmask_cnt - 1] = netmask; - for (i = node->netmask_cnt - 2; i >= 0; i--) { - if (netmask < node->netmasks[i]) { - node->netmasks[i + 1] = netmask; + for (i = node->netmask_cnt - 1; i > 0; i--) { + if (netmask < node->netmasks[i - 1]) { + node->netmasks[i] = netmask; break; } - node->netmasks[i + 1] = node->netmasks[i]; - node->netmasks[i] = netmask; + node->netmasks[i] = node->netmasks[i - 1]; + node->netmasks[i - 1] = netmask; } } } else { @@ -811,40 +811,20 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen, node->netmasks[node->netmask_cnt - 1] = netmask; - for (i = node->netmask_cnt - 2; i >= 0; i--) { - if (netmask < node->netmasks[i]) { - node->netmasks[i + 1] = netmask; + for (i = node->netmask_cnt - 1; i > 0; i--) { + if (netmask < node->netmasks[i - 1]) { + node->netmasks[i] = netmask; break; } - node->netmasks[i + 1] = node->netmasks[i]; - node->netmasks[i] = netmask; + node->netmasks[i] = node->netmasks[i - 1]; + node->netmasks[i - 1] = netmask; } } return new_node; } -/** - * \brief Adds a new generic key to the Radix tree - * - * \param key_stream Data that has to be added to the Radix tree - * \param key_bitlen The bitlen of the the above stream. For example if the - * stream is the string "abcd", the bitlen would be 32 - * \param tree Pointer to the Radix tree - * \param user Pointer to the user data that has to be associated with the - * key - * - * \retval node Pointer to the newly created node - */ -SCRadixNode *SCRadixAddKeyGeneric(uint8_t *key_stream, uint16_t key_bitlen, - SCRadixTree *tree, void *user) -{ - SCRadixNode *node = SCRadixAddKey(key_stream, key_bitlen, tree, user, 255); - - return node; -} - /** * \brief Adds a new IPV4 address to the Radix tree * @@ -1482,7 +1462,7 @@ static inline SCRadixNode *SCRadixFindKeyIPNetblock( * \param exact_match The key to be searched is an ip address * \param netmask Netmask used during exact match */ -static SCRadixNode *SCRadixFindKey(uint8_t *key_stream, uint16_t key_bitlen, uint8_t netmask, +static SCRadixNode *SCRadixFindKey(uint8_t *key_stream, uint8_t key_bitlen, uint8_t netmask, SCRadixTree *tree, int exact_match, void **user_data_result) { if (tree == NULL || tree->head == NULL) @@ -1493,9 +1473,6 @@ static SCRadixNode *SCRadixFindKey(uint8_t *key_stream, uint16_t key_bitlen, uin int bytes = 0; uint8_t tmp_stream[255]; - if (key_bitlen > 255) - return NULL; - memset(tmp_stream, 0, 255); memcpy(tmp_stream, key_stream, key_bitlen / 8); @@ -1538,19 +1515,6 @@ static SCRadixNode *SCRadixFindKey(uint8_t *key_stream, uint16_t key_bitlen, uin return ret; } -/** - * \brief Checks if a key is present in the tree - * - * \param key_stream Data that has to be found in the Radix tree - * \param key_bitlen The bitlen of the the above stream. - * \param tree Pointer to the Radix tree instance - */ -SCRadixNode *SCRadixFindKeyGeneric(uint8_t *key_stream, uint16_t key_bitlen, - SCRadixTree *tree, void **user_data_result) -{ - return SCRadixFindKey(key_stream, key_bitlen, 0, tree, 1, user_data_result); /* TODO netmask? */ -} - /** * \brief Checks if an IPV4 address is present in the tree * diff --git a/src/util-radix-tree.h b/src/util-radix-tree.h index e9e63457c6..894af16c34 100644 --- a/src/util-radix-tree.h +++ b/src/util-radix-tree.h @@ -66,7 +66,7 @@ typedef struct SCRadixNode_ { uint16_t pad0; /* total no of netmasks that are registered under this node */ - int netmask_cnt; + uint16_t netmask_cnt; /* holds a list of netmaks that come under this node in the tree */ uint8_t *netmasks; @@ -101,7 +101,6 @@ void SCRadixChopIPAddressAgainstNetmask(uint8_t *, uint8_t, uint16_t); SCRadixTree *SCRadixCreateRadixTree(void (*Free)(void*), void (*PrintData)(void*)); void SCRadixReleaseRadixTree(SCRadixTree *); -SCRadixNode *SCRadixAddKeyGeneric(uint8_t *, uint16_t, SCRadixTree *, void *); SCRadixNode *SCRadixAddKeyIPV4(uint8_t *, SCRadixTree *, void *); SCRadixNode *SCRadixAddKeyIPV6(uint8_t *, SCRadixTree *, void *); SCRadixNode *SCRadixAddKeyIPV4Netblock(uint8_t *, SCRadixTree *, void *, @@ -117,8 +116,6 @@ void SCRadixRemoveKeyIPV4(uint8_t *, SCRadixTree *); void SCRadixRemoveKeyIPV6Netblock(uint8_t *, SCRadixTree *, uint8_t); void SCRadixRemoveKeyIPV6(uint8_t *, SCRadixTree *); -SCRadixNode *SCRadixFindKeyGeneric(uint8_t *, uint16_t, SCRadixTree *, void **); - SCRadixNode *SCRadixFindKeyIPV4ExactMatch(uint8_t *, SCRadixTree *, void **); SCRadixNode *SCRadixFindKeyIPV4Netblock(uint8_t *, SCRadixTree *, uint8_t, void **); SCRadixNode *SCRadixFindKeyIPV4BestMatch(uint8_t *, SCRadixTree *, void **); diff --git a/src/util-spm-bm.c b/src/util-spm-bm.c index efbb756181..8bdd347dfe 100644 --- a/src/util-spm-bm.c +++ b/src/util-spm-bm.c @@ -38,6 +38,7 @@ #include "util-debug.h" #include "util-error.h" #include "util-memcpy.h" +#include "util-validate.h" static int PreBmGs(const uint8_t *x, uint16_t m, uint16_t *bmGs); static void PreBmBc(const uint8_t *x, uint16_t m, uint16_t *bmBc); @@ -137,7 +138,7 @@ void BoyerMooreCtxDeInit(BmCtx *bmctx) */ static void PreBmBc(const uint8_t *x, uint16_t m, uint16_t *bmBc) { - int32_t i; + uint16_t i; for (i = 0; i < 256; ++i) { bmBc[i] = m; @@ -168,7 +169,8 @@ static void BoyerMooreSuffixes(const uint8_t *x, uint16_t m, uint16_t *suff) f = i; while (g >= 0 && x[g] == x[g + m - 1 - f]) --g; - suff[i] = f - g; + DEBUG_VALIDATE_BUG_ON(f - g < 0 || f - g > UINT16_MAX); + suff[i] = (uint16_t)(f - g); } } } @@ -197,10 +199,10 @@ static int PreBmGs(const uint8_t *x, uint16_t m, uint16_t *bmGs) if (i == -1 || suff[i] == i + 1) for (; j < m - 1 - i; ++j) if (bmGs[j] == m) - bmGs[j] = m - 1 - i; + bmGs[j] = (uint16_t)(m - 1 - i); for (i = 0; i <= m - 2; ++i) - bmGs[m - 1 - suff[i]] = m - 1 - i; + bmGs[m - 1 - suff[i]] = (uint16_t)(m - 1 - i); return 0; } @@ -214,14 +216,14 @@ static int PreBmGs(const uint8_t *x, uint16_t m, uint16_t *bmGs) */ static void PreBmBcNocase(const uint8_t *x, uint16_t m, uint16_t *bmBc) { - int32_t i; + uint16_t i; for (i = 0; i < 256; ++i) { bmBc[i] = m; } for (i = 0; i < m - 1; ++i) { - bmBc[u8_tolower((unsigned char)x[i])] = m - 1 - i; - bmBc[u8_toupper((unsigned char)x[i])] = m - 1 - i; + bmBc[u8_tolower(x[i])] = m - 1 - i; + bmBc[u8_toupper(x[i])] = m - 1 - i; } } @@ -243,7 +245,8 @@ static void BoyerMooreSuffixesNocase(const uint8_t *x, uint16_t m, while (g >= 0 && u8_tolower(x[g]) == u8_tolower(x[g + m - 1 - f])) { --g; } - suff[i] = f - g; + DEBUG_VALIDATE_BUG_ON(f - g < 0 || f - g > UINT16_MAX); + suff[i] = (uint16_t)(f - g); } } } @@ -258,7 +261,7 @@ static void BoyerMooreSuffixesNocase(const uint8_t *x, uint16_t m, */ static void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs) { - int32_t i, j; + uint16_t i, j; uint16_t suff[m + 1]; BoyerMooreSuffixesNocase(x, m, suff); @@ -267,11 +270,11 @@ static void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs) bmGs[i] = m; } j = 0; - for (i = m - 1; i >= 0; --i) { - if (i == -1 || suff[i] == i + 1) { - for (; j < m - 1 - i; ++j) { + for (i = m; i > 0; --i) { + if (suff[i-1] == i) { + for (; j < m - i; ++j) { if (bmGs[j] == m) { - bmGs[j] = m - 1 - i; + bmGs[j] = m - i; } } } diff --git a/src/util-thash.c b/src/util-thash.c index a46a0e3f8e..90ecb2694d 100644 --- a/src/util-thash.c +++ b/src/util-thash.c @@ -231,8 +231,7 @@ static int THashInitConfig(THashTableContext *ctx, const char *cnf_prefix) GET_VAR(cnf_prefix, "hash-size"); if ((ConfGet(varname, &conf_val)) == 1) { - if (StringParseUint32(&configval, 10, strlen(conf_val), - conf_val) > 0) { + if (StringParseUint32(&configval, 10, (uint16_t)strlen(conf_val), conf_val) > 0) { ctx->config.hash_size = configval; } } @@ -240,8 +239,7 @@ static int THashInitConfig(THashTableContext *ctx, const char *cnf_prefix) GET_VAR(cnf_prefix, "prealloc"); if ((ConfGet(varname, &conf_val)) == 1) { - if (StringParseUint32(&configval, 10, strlen(conf_val), - conf_val) > 0) { + if (StringParseUint32(&configval, 10, (uint16_t)strlen(conf_val), conf_val) > 0) { ctx->config.prealloc = configval; } else { WarnInvalidConfEntry(varname, "%"PRIu32, ctx->config.prealloc); diff --git a/src/util-threshold-config.c b/src/util-threshold-config.c index d22a755a75..5eedd864d7 100644 --- a/src/util-threshold-config.c +++ b/src/util-threshold-config.c @@ -856,7 +856,7 @@ static int ParseThresholdRule(DetectEngineCtx *de_ctx, char *rawstr, /* TODO: implement option "apply_to" */ - if (StringParseUint32(&parsed_timeout, 10, strlen(th_timeout), th_timeout) <= 0) { + if (StringParseUint32(&parsed_timeout, 10, sizeof(th_timeout), th_timeout) <= 0) { goto error; } @@ -904,7 +904,7 @@ static int ParseThresholdRule(DetectEngineCtx *de_ctx, char *rawstr, goto error; } - if (StringParseUint32(&parsed_count, 10, strlen(th_count), th_count) <= 0) { + if (StringParseUint32(&parsed_count, 10, sizeof(th_count), th_count) <= 0) { goto error; } if (parsed_count == 0) { @@ -912,7 +912,7 @@ static int ParseThresholdRule(DetectEngineCtx *de_ctx, char *rawstr, goto error; } - if (StringParseUint32(&parsed_seconds, 10, strlen(th_seconds), th_seconds) <= 0) { + if (StringParseUint32(&parsed_seconds, 10, sizeof(th_seconds), th_seconds) <= 0) { goto error; } @@ -935,11 +935,11 @@ static int ParseThresholdRule(DetectEngineCtx *de_ctx, char *rawstr, break; } - if (StringParseUint32(&id, 10, strlen(th_sid), th_sid) <= 0) { + if (StringParseUint32(&id, 10, sizeof(th_sid), th_sid) <= 0) { goto error; } - if (StringParseUint32(&gid, 10, strlen(th_gid), th_gid) <= 0) { + if (StringParseUint32(&gid, 10, sizeof(th_gid), th_gid) <= 0) { goto error; } diff --git a/src/util-var-name.c b/src/util-var-name.c index 3cc1231026..426ea146d2 100644 --- a/src/util-var-name.c +++ b/src/util-var-name.c @@ -61,7 +61,7 @@ static SCMutex g_varnamestore_staging_m = SCMUTEX_INITIALIZER; /** \brief Name2idx mapping structure for flowbits, flowvars and pktvars. */ typedef struct VariableName_ { char *name; - uint8_t type; /* flowbit, pktvar, etc */ + enum VarTypes type; /* flowbit, pktvar, etc */ uint32_t idx; } VariableName;