From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:58780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ry86l-0008ER-UP for qemu-devel@nongnu.org; Thu, 16 Feb 2012 15:39:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ry86h-0000k2-Hk for qemu-devel@nongnu.org; Thu, 16 Feb 2012 15:39:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ry86h-0000jU-9T for qemu-devel@nongnu.org; Thu, 16 Feb 2012 15:39:11 -0500 Message-ID: <4F3D6966.8090401@redhat.com> Date: Thu, 16 Feb 2012 13:39:02 -0700 From: Eric Blake MIME-Version: 1.0 References: In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigAE0D69FD88DDAE25A77886C6" Subject: Re: [Qemu-devel] [PATCH 2/2] pci: rewrite devaddr parsing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: malc Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigAE0D69FD88DDAE25A77886C6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 02/16/2012 12:23 PM, malc wrote: > On Thu, 16 Feb 2012, Michael S. Tsirkin wrote: >=20 >> Use scanf instead of manual string scanning. >> >> + >> + /* Parse [[:]:] */ >> + sscanf(addr, "%x:%x:%x%n", &dom, &bus, &slot, &n); >=20 > sscanf can fail. Worse, the *scanf family has undefined behavior on integer overflow. If addr contains "100000000000000:0:0", there's no telling whether it will be diagnosed as a parse error, or silently accepted and truncated, in which case, there's no telling what dom will contain. I cringe any time I see someone using scanf to parse numbers from arbitrary user input; I barely tolerate it for parsing things generated by the kernel, but even there, I won't ever use scanf myself. Same goes for atoi. _Only_ strtol and friends can robustly parse arbitrary input into integers. --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigAE0D69FD88DDAE25A77886C6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJPPWlmAAoJEKeha0olJ0Nq+qUH/iZr0tILPpC2snSQicCpmPDJ yqPqprNRsHZW7qIsJ/vFOhcPK3OUHXL4Uu4XsW0cmqFVOQ+MDAFtNujNOYgJW4xm KfAcuJMNpdOZJ7gtLxTZ+4htS2959XvcaAh1wl4qFYjHLUT2TASXlreBjrw0cF9O 26Ljk6jkfDtIcwHViLOp05jtqMhCOH592qZ5fQY2WAZWmwpbkDjhs6jQeK6Q/tyR zP1HPB5WEdRHtYNwKk9hyTr6oqIKWRZ6G8lPcXoUgyx6XjaOntX87DHHyjY6ixkT xG+JN3JlTtflT47AWvUyp+Ibm1zdMAcEqv1/amgeVlPwn7pHEk6NM61yZ+37NYA= =s92F -----END PGP SIGNATURE----- --------------enigAE0D69FD88DDAE25A77886C6--