From: Eric Blake Subject: Re: [Qemu-devel] [PATCH] xen-disk: use g_malloc0 to fix build Date: Fri, 28 Jul 2017 07:43:59 -0500 Message-ID: References: <20170728123127.27921-1-olaf@aepfle.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0843655715957251733==" Return-path: Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1db4cg-0002HA-6L for xen-devel@lists.xenproject.org; Fri, 28 Jul 2017 12:44:06 +0000 In-Reply-To: <20170728123127.27921-1-olaf@aepfle.de> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: Olaf Hering , Stefano Stabellini , Anthony Perard , Kevin Wolf , Max Reitz , "open list:X86" , "open list:Block layer core" , "open list:All patches CC here" List-Id: xen-devel@lists.xenproject.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --===============0843655715957251733== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="WaaktNbJxuOfPjEoUTMfoCtnsx2m6nAOV" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --WaaktNbJxuOfPjEoUTMfoCtnsx2m6nAOV Content-Type: multipart/mixed; boundary="TP7OW9RKoquW8S2S6HfPDVSV9mQUwROIu"; protected-headers="v1" From: Eric Blake To: Olaf Hering , Stefano Stabellini , Anthony Perard , Kevin Wolf , Max Reitz , "open list:X86" , "open list:Block layer core" , "open list:All patches CC here" Message-ID: Subject: Re: [Qemu-devel] [PATCH] xen-disk: use g_malloc0 to fix build References: <20170728123127.27921-1-olaf@aepfle.de> In-Reply-To: <20170728123127.27921-1-olaf@aepfle.de> --TP7OW9RKoquW8S2S6HfPDVSV9mQUwROIu Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 07/28/2017 07:31 AM, Olaf Hering wrote: > g_malloc0_n is available since glib-2.24. To allow build with older gli= b > versions use the generic g_malloc0, which is already used in many other= > places in the code. >=20 > Fixes commit 3284fad728 ("xen-disk: add support for multi-page shared r= ings") >=20 > Signed-off-by: Olaf Hering > --- > hw/block/xen_disk.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c > index d42ed7070d..71deec17b0 100644 > --- a/hw/block/xen_disk.c > +++ b/hw/block/xen_disk.c > @@ -1232,7 +1232,7 @@ static int blk_connect(struct XenDevice *xendev) > return -1; > } > =20 > - domids =3D g_malloc0_n(blkdev->nr_ring_ref, sizeof(uint32_t)); > + domids =3D g_malloc0(blkdev->nr_ring_ref * sizeof(uint32_t)); This version is prone to multiplication overflow (well, maybe not, but you have to audit for that). Wouldn't it be better to use: domids =3D g_new0(blkdev->nr_ring_ref, uint32_t) which preserves the safety of g_malloc0_n? --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org --TP7OW9RKoquW8S2S6HfPDVSV9mQUwROIu-- --WaaktNbJxuOfPjEoUTMfoCtnsx2m6nAOV Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEzBAEBCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAll7MY8ACgkQp6FrSiUn Q2pFBAf+J2Kjw9u1vblnf+cwlD30cZAsh55WbfKScq+ZobQaIWFhihCyRewu28F5 2IOusRGdJX48SQLJ8BcdRBwxwHLF7IGeWzuQR6F4oyfG+XGVR/ym5jqIK7QCz652 M8gCfsHFBhAn8Ukrx5Rz9u/dUndt7YJCG+duD4xLBgVLKNXd5CMhXfc0OOKHjgI/ qOYM7Rl8aIZOgHz9KPUfL/rowjuhVi8o/HUCzYxagNluQ5OFbh+fpj042jr1hexk oQdgH7PZ+uGbns7DdDAs/f9K3NXmJ0OEjPYTrUnLeSRqguIHFCl0u0E620ju4lbF 4C0n5WLeXYVhrrR6Iqsh06fWzakUNQ== =pAog -----END PGP SIGNATURE----- --WaaktNbJxuOfPjEoUTMfoCtnsx2m6nAOV-- --===============0843655715957251733== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --===============0843655715957251733==--