]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/varname: check id before unregister
authorShivani Bhardwaj <shivani@oisf.net>
Mon, 3 Nov 2025 04:54:48 +0000 (10:24 +0530)
committerVictor Julien <vjulien@oisf.net>
Mon, 3 Nov 2025 18:58:23 +0000 (18:58 +0000)
In case of an error a varname id is set to 0. Ideally, it shouldn't be
found in the hash table lookup but add a check anyway to avoid obtaining
the mutex lock and performing the lookup.

src/util-var-name.c

index a81920f3515a5518b84890a6eba28184d029a9b6..a24c9f4874decfb43767512bad2775482fddaf0c 100644 (file)
@@ -203,6 +203,10 @@ const char *VarNameStoreSetupLookup(const uint32_t id, const enum VarTypes type)
 
 void VarNameStoreUnregister(const uint32_t id, const enum VarTypes type)
 {
+    if (unlikely(id == 0)) {
+        /* There was an error registering the varname, so nothing to unregister */
+        return;
+    }
     SCMutexLock(&base_lock);
     VariableName lookup = { .type = type, .id = id };
     VariableName *found = (VariableName *)HashListTableLookup(base.ids, (void *)&lookup, 0);