From 1d89cad3436f9d7185798d27bc9b9211044b987c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 23 Jun 2011 11:26:38 +0100 Subject: [PATCH] dbus_realloc: don't crash if realloc() returns NULL while using guards Reviewed-by: Guillaume Desmottes Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41048 --- dbus/dbus-memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index c5f464137..08698d43e 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -588,8 +588,11 @@ dbus_realloc (void *memory, block = realloc (((unsigned char*)memory) - GUARD_START_OFFSET, bytes + GUARD_EXTRA_SIZE); - old_bytes = *(dbus_uint32_t*)block; - if (block && bytes >= old_bytes) + if (block == NULL) + return NULL; + + old_bytes = *(dbus_uint32_t*)block; + if (bytes >= old_bytes) /* old guards shouldn't have moved */ check_guards (((unsigned char*)block) + GUARD_START_OFFSET, FALSE); -- 2.47.3