]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
device: don't crash on unix command 'iface-bypassed-stat'
authorVictor Julien <vjulien@oisf.net>
Tue, 14 May 2024 04:45:30 +0000 (06:45 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 15 May 2024 05:12:27 +0000 (07:12 +0200)
In the default config iface bypass support is not enabled,
and storage API not initialized for it. Using it will lead to a crash.

This commit first checks if the device storage API is initialized.

Bug: #7022.

src/util-device.c

index a329be4786ba84cb5ddf17291b0a957ff5a19f8c..fd4cf5685f0b8936548bb0fd8a1a467fe5f2091e 100644 (file)
@@ -565,8 +565,11 @@ void LiveDevAddBypassSuccess(LiveDevice *dev, uint64_t cnt, int family)
 #ifdef BUILD_UNIX_SOCKET
 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer, void *data)
 {
+    if (g_bypass_storage_id.id < 0) {
+        json_object_set_new(answer, "message", json_string("Bypass not enabled"));
+        SCReturnInt(TM_ECODE_FAILED);
+    }
     LiveDevice *ldev = NULL, *ndev = NULL;
-
     json_t *ifaces = NULL;
     while(LiveDeviceForEach(&ldev, &ndev)) {
         BypassInfo *bpinfo = LiveDevGetStorageById(ldev, g_bypass_storage_id);