From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK7RD-00054a-8G for qemu-devel@nongnu.org; Fri, 15 Jan 2016 11:41:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aK7RA-0005fd-IU for qemu-devel@nongnu.org; Fri, 15 Jan 2016 11:41:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK7RA-0005fY-CU for qemu-devel@nongnu.org; Fri, 15 Jan 2016 11:41:20 -0500 References: <1452689507-8188-1-git-send-email-caoj.fnst@cn.fujitsu.com> <1452689507-8188-3-git-send-email-caoj.fnst@cn.fujitsu.com> <5698214D.1080503@redhat.com> <5698636C.9020102@cn.fujitsu.com> From: Eric Blake Message-ID: <5699212E.5070000@redhat.com> Date: Fri, 15 Jan 2016 09:41:18 -0700 MIME-Version: 1.0 In-Reply-To: <5698636C.9020102@cn.fujitsu.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7Op3NFFqKdv9KFa5nMm4b22BEghUCnFTm" Subject: Re: [Qemu-devel] [PATCH v5 2/5] Add Error **errp for xen_host_pci_device_get() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cao jin , qemu-devel@nongnu.org Cc: stefano.stabellini@eu.citrix.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7Op3NFFqKdv9KFa5nMm4b22BEghUCnFTm Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01/14/2016 08:11 PM, Cao jin wrote: >>> buf[rc] =3D 0; >>> - rc =3D qemu_strtoul(buf, &endptr, base, &value); >>> - if (!rc) { >>> - *pvalue =3D value; >>> + rc =3D qemu_strtoul(buf, &endptr, base, (unsigned long *)pvalue)= ; >> >> Ouch. Casting unsigned int * to unsigned long * and then dereferencing= >> it is bogus (you end up having qemu_strtoul() write beyond bounds on >> platforms where long is larger than int). >=20 > Yes, I considered this issue a little. Because the current condition is= : > the value it want to get won`t exceed 4 byte (vendor/device ID, etc). S= o > I guess even if on x86_64(length of int !=3D long), it won`t break thin= gs. > So, compared with following, which style do you prefer? Maybe: rc =3D qemu_strtoul(buf, &endptr, base, &value); if (rc) { assert(value < UINT_MAX); *pvalue =3D value; } else { report error ... } And maybe some of it should even be done as part of the conversion to qemu_strtoul() in 1/5. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --7Op3NFFqKdv9KFa5nMm4b22BEghUCnFTm Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWmSEuAAoJEKeha0olJ0Nqa1MH/RqpGxqfShETtSZUrqOp8Voo jsVTH9YtNFWPPWjs55KK1PZxtbR99+HqzGjBp3sH+KwAqlk4rZTkYdNO6VWQpel/ TTKn/HtfHJ0+YF8COkWLpWRS5PEx+3bGFEgP0U0NnqI6ihg67whA5jeVztk4lzgn jA2ajSBDR98SU8qdoCDG77kQq8DdhtDa5ukgJKppslqzzlQytpav/CPLbIzv3xCD /wh9U1WMlMR9P+6ZfPCbEAwmhijrAcCjfSSgXyIAe3pdaIV1UoGPZg9OgMd2rwjT 4h+vWI5sW1fTB9RXkcofSGxFkw5iO8UZZmcljx1btpPuP0FbBl+APCDydBwpvAg= =UP8+ -----END PGP SIGNATURE----- --7Op3NFFqKdv9KFa5nMm4b22BEghUCnFTm--