Received: from eggs.gnu.org ([208.118.235.92]:57327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXZIx-0004an-Rz for qemu-devel@nongnu.org; Thu, 24 May 2012 10:46:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SXZIr-00072I-LI for qemu-devel@nongnu.org; Thu, 24 May 2012 10:46:19 -0400 Received: from mx.meyering.net ([88.168.87.75]:40822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXZIr-00072B-E3 for qemu-devel@nongnu.org; Thu, 24 May 2012 10:46:13 -0400 From: Jim Meyering In-Reply-To: <1337173681-25891-7-git-send-email-jim@meyering.net> (Jim Meyering's message of "Wed, 16 May 2012 15:08:01 +0200") References: <1337173681-25891-1-git-send-email-jim@meyering.net> <1337173681-25891-7-git-send-email-jim@meyering.net> Date: Thu, 24 May 2012 16:46:11 +0200 Message-ID: <87r4u9ab7w.fsf_-_@rho.meyering.net> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v2 6/6] softmmu-semi: fix lock_user* functions not to deref NULL upon OOM List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Weil , Anthony Liguori , Andreas F=E4rber , Andreas =?iso-8859-1?Q?F=E4rber?= , Matthew Fernandez Return NULL upon malloc failure. Signed-off-by: Jim Meyering --- Improved based on suggestion from Peter Maydell: Handle malloc failure rather than relying on g_malloc, since we can't afford to let guest-provided "len" induce g_malloc's abort. softmmu-semi.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/softmmu-semi.h b/softmmu-semi.h index 648cb95..bcb979a 100644 --- a/softmmu-semi.h +++ b/softmmu-semi.h @@ -40,7 +40,7 @@ static void *softmmu_lock_user(CPUArchState *env, uint32_t addr, uint32_t len, uint8_t *p; /* TODO: Make this something that isn't fixed size. */ p = malloc(len); - if (copy) + if (p && copy) cpu_memory_rw_debug(env, addr, p, len, 0); return p; } @@ -52,6 +52,9 @@ static char *softmmu_lock_user_string(CPUArchState *env, uint32_t addr) uint8_t c; /* TODO: Make this something that isn't fixed size. */ s = p = malloc(1024); + if (!s) { + return NULL; + } do { cpu_memory_rw_debug(env, addr, &c, 1, 0); addr++; -- 1.7.10.2.565.gbd578b5