From: Arran Cudbard-Bell Date: Thu, 31 Mar 2022 16:35:02 +0000 (-0600) Subject: Check for NULL heap pointers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=baad8e0d4c2fa56e2b08666fb594ca266ecda7f7;p=thirdparty%2Ffreeradius-server.git Check for NULL heap pointers --- diff --git a/src/lib/util/heap.c b/src/lib/util/heap.c index 06622189a5..efefdc8746 100644 --- a/src/lib/util/heap.c +++ b/src/lib/util/heap.c @@ -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];