From 92884b9f4305706043a1ce07fe964ba14edcba83 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 28 Apr 2022 08:58:47 +0200 Subject: [PATCH] device: limit device id to uint16_t Meaning that we support 65535 live devices at the most --- src/util-device.c | 8 +++++++- src/util-device.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) 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);