]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/radix-tree: fix potential dereference of nullptr
authorAlexey Simakov <bigalex934@gmail.com>
Tue, 28 May 2024 16:36:58 +0000 (19:36 +0300)
committerVictor Julien <victor@inliniac.net>
Sat, 1 Jun 2024 18:31:09 +0000 (20:31 +0200)
Fix potential dereferece of nullptr in case of
unsuccessful allocation of memory leak for tree nodes

Bug: #7049

src/util-radix-tree.c

index 0f570fdbc9f8d20d55d396a3f7b316cdd675d64e..1b378338f75876933ce65e317daf2b145f4242cd 100644 (file)
@@ -700,6 +700,13 @@ static SCRadixNode *SCRadixAddKeyInternal(uint8_t *key_stream, uint8_t key_bitle
         return NULL;
     }
     new_node = SCRadixCreateNode();
+
+    if (new_node == NULL) {
+        SCRadixReleasePrefix(prefix, tree);
+        sc_errno = SC_ENOMEM;
+        return NULL;
+    }
+
     new_node->prefix = prefix;
     new_node->bit = prefix->bitlen;
 
@@ -730,6 +737,13 @@ static SCRadixNode *SCRadixAddKeyInternal(uint8_t *key_stream, uint8_t key_bitle
          * detail below) */
     } else {
         inter_node = SCRadixCreateNode();
+
+        if (inter_node == NULL) {
+            SCRadixReleaseNode(new_node, tree);
+            sc_errno = SC_ENOMEM;
+            return NULL;
+        }
+
         inter_node->prefix = NULL;
         inter_node->bit = differ_bit;
         inter_node->parent = node->parent;