Received: from eggs.gnu.org ([208.118.235.92]:57388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXZJN-0005M5-Ix for qemu-devel@nongnu.org; Thu, 24 May 2012 10:46:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SXZJG-00075n-1N for qemu-devel@nongnu.org; Thu, 24 May 2012 10:46:45 -0400 Received: from mx.meyering.net ([88.168.87.75]:40830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXZJF-00075g-Qy for qemu-devel@nongnu.org; Thu, 24 May 2012 10:46:37 -0400 From: Jim Meyering In-Reply-To: (Peter Maydell's message of "Sat, 19 May 2012 16:46:44 +0100") 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:36 +0200 Message-ID: <87likhab77.fsf@rho.meyering.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 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: Peter Maydell Cc: Anthony Liguori , qemu-devel@nongnu.org, Stefan Weil , Andreas F=E4rber , Andreas =?iso-8859-1?Q?F=E4rber?= , Matthew Fernandez Peter Maydell wrote: > On 16 May 2012 14:08, Jim Meyering wrote: >> From: Jim Meyering >> >> Use g_malloc/g_free in place of malloc/free. >> >> Signed-off-by: Jim Meyering >> --- >> =A0softmmu-semi.h | 6 +++--- >> =A01 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/softmmu-semi.h b/softmmu-semi.h >> index 648cb95..996e0f7 100644 >> --- a/softmmu-semi.h >> +++ b/softmmu-semi.h >> @@ -39,7 +39,7 @@ static void *softmmu_lock_user(CPUArchState *env, >> uint32_t addr, uint32_t len, >> =A0{ >> =A0 =A0 uint8_t *p; >> =A0 =A0 /* TODO: Make this something that isn't fixed size. =A0*/ >> - =A0 =A0p =3D malloc(len); >> + =A0 =A0p =3D g_malloc(len); >> =A0 =A0 if (copy) >> =A0 =A0 =A0 =A0 cpu_memory_rw_debug(env, addr, p, len, 0); >> =A0 =A0 return p; > > Nak. This function is called with a length passed from the guest, so > killing qemu if the length is too large is a bad idea. The callers > should handle it returning NULL on failure. (Most of them do already, > if any do not that's a bug.) The bug in this function is passing > NULL to cpu_memory_rw_debug(). That makes sense. I've adjusted as you suggest and posted a V2.