diff options
author | Anatoly Burakov <anatoly.burakov@intel.com> | 2018-04-16 16:04:27 +0100 |
---|---|---|
committer | Thomas Monjalon <thomas@monjalon.net> | 2018-04-27 23:52:51 +0200 |
commit | 64b6fcb1610814c68b3f6fe57f59732b98502aa3 (patch) | |
tree | 154fa19fedae2f05539f3fe17e23693d34f5c52a | |
parent | 0af8db317267544e86b271008360d9847973f92c (diff) | |
download | dpdk-64b6fcb1610814c68b3f6fe57f59732b98502aa3.zip dpdk-64b6fcb1610814c68b3f6fe57f59732b98502aa3.tar.gz dpdk-64b6fcb1610814c68b3f6fe57f59732b98502aa3.tar.xz |
malloc: check for heap corruption
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")
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Harry van Haaren <harry.van.haaren@intel.com>
-rw-r--r-- | lib/librte_eal/common/malloc_elem.c | 6 |
1 files changed, 6 insertions, 0 deletions
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; |