diff --git a/src/runmode-pcap.c b/src/runmode-pcap.c index ec881ced4a87..6990aabea065 100644 --- a/src/runmode-pcap.c +++ b/src/runmode-pcap.c @@ -89,7 +89,7 @@ static void *ParsePcapConfig(const char *iface) if ((ConfGetInt("pcap.buffer-size", &value)) == 1) { if (value >= 0 && value <= INT_MAX) { SCLogInfo("Pcap will use %d buffer size", (int)value); - aconf->buffer_size = value; + aconf->buffer_size = (int)value; } else { SCLogWarning("pcap.buffer-size " "value of %" PRIiMAX " is invalid. Valid range is " @@ -207,8 +207,10 @@ static void *ParsePcapConfig(const char *iface) aconf->snaplen = 0; if (ConfGetChildValueIntWithDefault(if_root, if_default, "snaplen", &snaplen) != 1) { SCLogDebug("could not get snaplen or none specified"); + } else if (snaplen < INT_MIN || snaplen > INT_MAX) { + SCLogDebug("snaplen value is not in the accepted range"); } else { - aconf->snaplen = snaplen; + aconf->snaplen = (int)snaplen; } return aconf; diff --git a/src/runmode-unix-socket.c b/src/runmode-unix-socket.c index f82a9fdc1460..e0b314a1cd2a 100644 --- a/src/runmode-unix-socket.c +++ b/src/runmode-unix-socket.c @@ -831,6 +831,16 @@ TmEcode UnixSocketDatasetLookup(json_t *cmd, json_t *answer, void *data) } } +static bool JsonU32Value(json_t *jarg, uint32_t *ret) +{ + int64_t r = json_integer_value(jarg); + if (r < 0 || r > UINT32_MAX) { + return false; + } + *ret = (uint32_t)r; + return true; +} + /** * \brief Command to add a tenant handler * @@ -856,7 +866,12 @@ TmEcode UnixSocketRegisterTenantHandler(json_t *cmd, json_t* answer, void *data) json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - uint32_t tenant_id = json_integer_value(jarg); + uint32_t tenant_id; + if (!JsonU32Value(jarg, &tenant_id)) { + SCLogInfo("tenant_id is not a uint32"); + json_object_set_new(answer, "message", json_string("tenant_id is not a uint32")); + return TM_ECODE_FAILED; + } /* 2 get tenant handler type */ jarg = json_object_get(cmd, "htype"); @@ -937,7 +952,12 @@ TmEcode UnixSocketUnregisterTenantHandler(json_t *cmd, json_t* answer, void *dat json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - uint32_t tenant_id = json_integer_value(jarg); + uint32_t tenant_id; + if (!JsonU32Value(jarg, &tenant_id)) { + SCLogInfo("tenant_id is not a uint32"); + json_object_set_new(answer, "message", json_string("tenant_id is not a uint32")); + return TM_ECODE_FAILED; + } /* 2 get tenant handler type */ jarg = json_object_get(cmd, "htype"); @@ -1018,7 +1038,12 @@ TmEcode UnixSocketRegisterTenant(json_t *cmd, json_t* answer, void *data) json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - uint32_t tenant_id = json_integer_value(jarg); + uint32_t tenant_id; + if (!JsonU32Value(jarg, &tenant_id)) { + SCLogInfo("tenant_id is not a uint32"); + json_object_set_new(answer, "message", json_string("tenant_id is not a uint32")); + return TM_ECODE_FAILED; + } /* 2 get tenant yaml */ jarg = json_object_get(cmd, "filename"); @@ -1086,7 +1111,12 @@ TmEcode UnixSocketReloadTenant(json_t *cmd, json_t* answer, void *data) json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - uint32_t tenant_id = json_integer_value(jarg); + uint32_t tenant_id; + if (!JsonU32Value(jarg, &tenant_id)) { + SCLogInfo("tenant_id is not a uint32"); + json_object_set_new(answer, "message", json_string("tenant_id is not a uint32")); + return TM_ECODE_FAILED; + } /* 2 get tenant yaml */ jarg = json_object_get(cmd, "filename"); @@ -1180,7 +1210,12 @@ TmEcode UnixSocketUnregisterTenant(json_t *cmd, json_t* answer, void *data) json_object_set_new(answer, "message", json_string("id is not an integer")); return TM_ECODE_FAILED; } - uint32_t tenant_id = json_integer_value(jarg); + uint32_t tenant_id; + if (!JsonU32Value(jarg, &tenant_id)) { + SCLogInfo("tenant_id is not a uint32"); + json_object_set_new(answer, "message", json_string("tenant_id is not a uint32")); + return TM_ECODE_FAILED; + } SCLogInfo("remove-tenant: removing tenant %d", tenant_id); @@ -1271,14 +1306,24 @@ TmEcode UnixSocketHostbitAdd(json_t *cmd, json_t* answer, void *data_usused) json_object_set_new(answer, "message", json_string("expire is not an integer")); return TM_ECODE_FAILED; } - uint32_t expire = json_integer_value(jarg); + uint32_t expire; + if (!JsonU32Value(jarg, &expire)) { + SCLogInfo("expire is not a uint32"); + json_object_set_new(answer, "message", json_string("expire is not a uint32")); + return TM_ECODE_FAILED; + } SCLogInfo("add-hostbit: ip %s hostbit %s expire %us", ipaddress, hostbit, expire); SCTime_t current_time = TimeGet(); Host *host = HostGetHostFromHash(&a); if (host) { - HostBitSet(host, idx, SCTIME_SECS(current_time) + expire); + if (SCTIME_SECS(current_time) + expire > UINT32_MAX) { + json_object_set_new(answer, "message", json_string("couldn't set host expire")); + HostRelease(host); + return TM_ECODE_FAILED; + } + HostBitSet(host, idx, (uint32_t)(SCTIME_SECS(current_time) + expire)); HostRelease(host); json_object_set_new(answer, "message", json_string("hostbit added"));