From 5a9b8e7ee95edc8b78bbaaf842af5279ca720c39 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Thu, 17 Jan 2019 10:13:55 +0100 Subject: [PATCH] alloc: fix two potential NULL dereferences bzero() doesn't check its pointer argument for NULL, the caller has to avoid such calls. Signed-off-by: Guennadi Liakhovetski --- src/lib/alloc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/alloc.c b/src/lib/alloc.c index 561b32e5e..9b54f8a61 100644 --- a/src/lib/alloc.c +++ b/src/lib/alloc.c @@ -597,9 +597,12 @@ void *_malloc(int zone, uint32_t caps, size_t bytes) trace_mem_error("rmalloc() error: invalid zone"); break; } + #if DEBUG_BLOCK_FREE - bzero(ptr, bytes); + if (ptr) + bzero(ptr, bytes); #endif + spin_unlock_irq(&memmap.lock, flags); memmap.heap_trace_updated = 1; return ptr; @@ -691,7 +694,8 @@ out: ptr = cache_to_uncache(ptr); #if DEBUG_BLOCK_FREE - bzero(ptr, bytes); + if (ptr) + bzero(ptr, bytes); #endif spin_unlock_irq(&memmap.lock, flags);