From: Philippe Antoine Date: Thu, 28 Apr 2022 06:58:47 +0000 (+0200) Subject: device: limit device id to uint16_t X-Git-Tag: suricata-7.0.0-rc2~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92884b9f4305706043a1ce07fe964ba14edcba83;p=thirdparty%2Fsuricata.git device: limit device id to uint16_t Meaning that we support 65535 live devices at the most --- diff --git a/src/util-device.c b/src/util-device.c index 5eed6abdb5..74a51c9f10 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -132,6 +132,12 @@ int LiveRegisterDevice(const char *dev) return -1; } + int id = LiveGetDeviceCount(); + if (id > UINT16_MAX) { + SCFree(pd); + return -1; + } + pd->dev = SCStrdup(dev); if (unlikely(pd->dev == NULL)) { SCFree(pd); @@ -143,7 +149,7 @@ int LiveRegisterDevice(const char *dev) SC_ATOMIC_INIT(pd->pkts); SC_ATOMIC_INIT(pd->drop); SC_ATOMIC_INIT(pd->invalid_checksums); - pd->id = LiveGetDeviceCount(); + pd->id = (uint16_t)id; TAILQ_INSERT_TAIL(&live_devices, pd, next); SCLogDebug("Device \"%s\" registered and created.", dev); diff --git a/src/util-device.h b/src/util-device.h index ae9ec97c08..51ddf7d525 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -51,7 +51,7 @@ typedef struct LiveDevice_ { char dev_short[MAX_DEVNAME + 1]; bool tenant_id_set; - int id; + uint16_t id; SC_ATOMIC_DECLARE(uint64_t, pkts); SC_ATOMIC_DECLARE(uint64_t, drop);