[dpdk-dev] [PATCH v2 3/3] malloc: fix potential dereferencing of NULL pointer
Anatoly Burakov
anatoly.burakov at intel.com
Wed Apr 25 12:15:39 CEST 2018
Previous code checked for both first/last elements being NULL,
but if they weren't, the expectation was that they're both
non-NULL, which will be the case under normal conditions, but
may not be the case due to heap structure corruption.
Coverity issue: 272566
Fixes: bb372060dad4 ("malloc: make heap a doubly-linked list")
Cc: anatoly.burakov at intel.com
Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
---
lib/librte_eal/common/malloc_elem.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/librte_eal/common/malloc_elem.c b/lib/librte_eal/common/malloc_elem.c
index ee79dcd..af81961 100644
--- a/lib/librte_eal/common/malloc_elem.c
+++ b/lib/librte_eal/common/malloc_elem.c
@@ -49,6 +49,12 @@ malloc_elem_insert(struct malloc_elem *elem)
struct malloc_elem *prev_elem, *next_elem;
struct malloc_heap *heap = elem->heap;
+ /* first and last elements must be both NULL or both non-NULL */
+ if ((heap->first == NULL) != (heap->last == NULL)) {
+ RTE_LOG(ERR, EAL, "Heap is probably corrupt\n");
+ return;
+ }
+
if (heap->first == NULL && heap->last == NULL) {
/* if empty heap */
heap->first = elem;
--
2.7.4
More information about the dev
mailing list