From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhgI4-0002W4-PT for qemu-devel@nongnu.org; Thu, 01 Oct 2015 12:01:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhgI0-0003Wl-79 for qemu-devel@nongnu.org; Thu, 01 Oct 2015 12:01:04 -0400 Received: from mail-ig0-x234.google.com ([2607:f8b0:4001:c05::234]:33287) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhgHz-0003VY-9p for qemu-devel@nongnu.org; Thu, 01 Oct 2015 12:00:59 -0400 Received: by igbkq10 with SMTP id kq10so21831757igb.0 for ; Thu, 01 Oct 2015 09:00:58 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <560D57CF.1040401@redhat.com> References: <560D57CF.1040401@redhat.com> Date: Thu, 1 Oct 2015 21:30:58 +0530 Message-ID: From: Harmandeep Kaur Content-Type: multipart/alternative; boundary=089e013a282223bd0b05210d27da Subject: Re: [Qemu-devel] [PATCH v2] linux-user/syscall.c: malloc()/calloc() to g_malloc()/g_try_malloc()/g_new0() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Stefan Hajnoczi , Riku Voipio , qemu-devel --089e013a282223bd0b05210d27da Content-Type: text/plain; charset=UTF-8 Thank you Eric for guiding me in the right direction. I look forward to implement this correctly. On Thu, Oct 1, 2015 at 9:27 PM, Eric Blake wrote: > On 09/30/2015 11:32 PM, Harmandeep Kaur wrote: > > Convert malloc()/calloc() calls to g_malloc()/g_try_malloc()/g_new0() > > in linux-user/syscall.c file > > This part is fine, > > > > > v1->v2 convert the free() call in host_to_target_semarray() > > to g_free() and calls g_try_malloc(count) instead of > > g_try_malloc(sizeof(count)) > > but this part belongs... > > > > > Signed-off-by: Harmandeep Kaur > > --- > > ...here, after the --- separator. It is useful information to mail > reviewers, but worthless in the qemu.git history (a year from now, we > won't care how many versions it went through on the list, only the > version that got checked in). > > > > +++ b/linux-user/syscall.c > > @@ -1554,12 +1554,7 @@ set_timeout: > > } > > > > fprog.len = tswap16(tfprog->len); > > - filter = malloc(fprog.len * sizeof(*filter)); > > - if (filter == NULL) { > > - unlock_user_struct(tfilter, tfprog->filter, 1); > > - unlock_user_struct(tfprog, optval_addr, 1); > > - return -TARGET_ENOMEM; > > - } > > + filter = g_malloc(fprog.len * sizeof(*filter)); > > This should use g_new(TYPE, fprog.len) to avoid overflow issues. > > -- > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org > > --089e013a282223bd0b05210d27da Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thank you Eric for guiding me in the right direction.=
I look forward to implement this correctly.

On Thu, Oct 1, 2015 at 9:27= PM, Eric Blake <eblake@redhat.com> wrote:
On 09/30/2015 11:32 PM, Harmandeep Kaur w= rote:
> Convert malloc()/calloc() calls to g_malloc()/g_try_malloc()/g_new0()<= br> > in linux-user/syscall.c file

This part is fine,

>
> v1->v2=C2=A0 convert the free() call in host_to_target_semarray() > to g_free() and calls g_try_malloc(count)=C2=A0 instead of
> g_try_malloc(sizeof(count))

but this part belongs...

>
> Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
> ---

...here, after the --- separator.=C2=A0 It is useful information to = mail
reviewers, but worthless in the qemu.git history (a year from now, we
won't care how many versions it went through on the list, only the
version that got checked in).


> +++ b/linux-user/syscall.c
> @@ -1554,12 +1554,7 @@ set_timeout:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprog.le= n =3D tswap16(tfprog->len);
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 filter =3D ma= lloc(fprog.len * sizeof(*filter));
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (filter = =3D=3D NULL) {
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= unlock_user_struct(tfilter, tfprog->filter, 1);
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= unlock_user_struct(tfprog, optval_addr, 1);
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= return -TARGET_ENOMEM;
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 filter =3D g_= malloc(fprog.len * sizeof(*filter));

This should use g_new(TYPE, fprog.len) to avoid overflow issues.

--
Eric Blake=C2=A0 =C2=A0eblake redhat com=C2=A0 =C2=A0 +1-919-301-3266
Libvirt virtualization library http://libvirt.org


--089e013a282223bd0b05210d27da--