]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Check for NULL heap pointers
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 31 Mar 2022 16:35:02 +0000 (10:35 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 31 Mar 2022 16:35:02 +0000 (10:35 -0600)
src/lib/util/heap.c

index 06622189a56250961a6ff9a827a01b0b8f114ff6..efefdc8746715529ff6877baf7da30244eebcef5 100644 (file)
@@ -148,6 +148,11 @@ int fr_heap_insert(fr_heap_t **hp, void *data)
        fr_heap_t *h = *hp;
        fr_heap_index_t child;
 
+       if (unlikely(h == NULL)) {
+               fr_strerror_const("Heap pointer was NULL");
+               return -1;
+       }
+
        child = index_get(h, data);
        if (fr_heap_entry_inserted(child)) {
                fr_strerror_const("Node is already in the heap");
@@ -236,6 +241,11 @@ int fr_heap_extract(fr_heap_t **hp, void *data)
        fr_heap_t *h = *hp;
        fr_heap_index_t parent, child, max;
 
+       if (unlikely(h == NULL)) {
+               fr_strerror_const("Heap pointer was NULL");
+               return -1;
+       }
+
        /*
         *      Extract element.
         */
@@ -312,9 +322,13 @@ int fr_heap_extract(fr_heap_t **hp, void *data)
 void *fr_heap_pop(fr_heap_t **hp)
 {
        fr_heap_t *h = *hp;
-
        void *data;
 
+       if (unlikely(h == NULL)) {
+               fr_strerror_const("Heap pointer was NULL");
+               return -1;
+       }
+
        if (h->num_elements == 0) return NULL;
 
        data = h->p[1];