From 24ced3026fc8297129de1a9175b070248e30e8de Mon Sep 17 00:00:00 2001 From: Jim Munn Date: Thu, 12 Mar 2026 12:37:59 -0400 Subject: [PATCH] util/mem: fix NULL dereference in nvme_realloc() on allocation failure If nvme_alloc() fails and returns NULL, the subsequent memcpy() would dereference a NULL pointer, resulting in undefined behavior. Add a NULL check on the result of nvme_alloc() and return NULL early, consistent with standard realloc() semantics where the original pointer remains valid on failure. Signed-off-by: Jim Munn --- util/mem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/mem.c b/util/mem.c index d2be46e870..2b97632d82 100644 --- a/util/mem.c +++ b/util/mem.c @@ -29,6 +29,8 @@ void *nvme_realloc(void *p, size_t len) size_t old_len = malloc_usable_size(p); void *result = nvme_alloc(len); + if (!result) + return NULL; if (p) { memcpy(result, p, min(old_len, len));