]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
device: limit device id to uint16_t
authorPhilippe Antoine <contact@catenacyber.fr>
Thu, 28 Apr 2022 06:58:47 +0000 (08:58 +0200)
committerVictor Julien <vjulien@oisf.net>
Mon, 5 Jun 2023 09:08:21 +0000 (11:08 +0200)
Meaning that we support 65535 live devices at the most

src/util-device.c
src/util-device.h

index 5eed6abdb5dac7bf371e2c9aa050e877fb8a9fd2..74a51c9f1069c3539bc9b8952727b234f8de46fb 100644 (file)
@@ -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);
index ae9ec97c08b5e87d2cf4aeb61fb6e85741067894..51ddf7d5257a1b56054906d7ac1d41ab3acf5675 100644 (file)
@@ -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);