From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrS2Y-00084Z-Nc for qemu-devel@nongnu.org; Fri, 13 Dec 2013 07:40:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VrS2T-0005Mj-S6 for qemu-devel@nongnu.org; Fri, 13 Dec 2013 07:40:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrS2T-0005Lx-JS for qemu-devel@nongnu.org; Fri, 13 Dec 2013 07:40:17 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBDCeAqa005831 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Dec 2013 07:40:11 -0500 Message-ID: <52AB0028.407@redhat.com> Date: Fri, 13 Dec 2013 05:40:08 -0700 From: Eric Blake MIME-Version: 1.0 References: <1386929311-520-1-git-send-email-kraxel@redhat.com> In-Reply-To: <1386929311-520-1-git-send-email-kraxel@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="qSIx3HOQBmdbsQQARW2mwtunGiwPISF5l" Subject: Re: [Qemu-devel] [PATCH v3] inet_listen_opts: add error checking List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann , qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --qSIx3HOQBmdbsQQARW2mwtunGiwPISF5l Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 12/13/2013 03:08 AM, Gerd Hoffmann wrote: > Don't use atoi() function which doesn't detect errors, switch to > strtol and error out on failures. Also add a range check while > being at it. >=20 > [ v3: oops, v2 didn't build ] > [ v2: use parse_uint_full instead of strtol ] Patch changelog belongs... >=20 > Signed-off-by: Gerd Hoffmann > --- =2E..here, so that 'git am' will strip it (it's useful for reviewers on list, but not in 'git log', where you no longer have access to v1 or v2).= > util/qemu-sockets.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) >=20 > diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c > index 6b97dc1..c3560c1 100644 > --- a/util/qemu-sockets.c > +++ b/util/qemu-sockets.c > @@ -133,8 +133,18 @@ int inet_listen_opts(QemuOpts *opts, int port_offs= et, Error **errp) > ai.ai_family =3D PF_INET6; > =20 > /* lookup */ > - if (port_offset) > - snprintf(port, sizeof(port), "%d", atoi(port) + port_offset); > + if (port_offset) { > + int baseport; > + if (parse_uint_full(port, &baseport, 10) < 0) { parse_uint_full takes an 'unsigned long long *', but you are passing an 'int *'. I'm surprised it compiled for you. It causes a buffer overflow if the pointer is assigned to, and gives different results depending on platform endianness. > + error_setg(errp, "can't convert to a number: %s", port); > + return -1; > + } > + if (baseport < 0 || baseport + port_offset > 65535) { > + error_setg(errp, "port %s out of range", port); But errno is not set to a sane value at this point, so error_setg() is wrong. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --qSIx3HOQBmdbsQQARW2mwtunGiwPISF5l 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.15 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSqwAoAAoJEKeha0olJ0NqchsIAIx7O9SFvH56w9AIEenA7HPU rJQSju6g43vT1ekTIqpHX0s9hvdPZanmH62ur5xvodgsBbL476ghx3lQixEvUOLC yjvadN4xMlfubliYUCEmd0jRwWvjfIDHKnO4Pxnmu60I0Ogzz/BHC0ymO5T2MkIs 1uZ1LlfIBLgAwWBc6t0AZvjZTUSLMx+YfkAJ2GuKZuizagcK75CY9T3GigfEAZZS b/KgV2qE0NjVNLmPmJCa0MQiNEK2TpxdfIU+8H+hu9tGYq/o+D7/vPRBNmEjFU3Z GxIEF2O4OFPatrV3UXAzJcEdbynAr8n2ww4kncGXF6yX/K5d+T5wEAJnBOR09dc= =XdNU -----END PGP SIGNATURE----- --qSIx3HOQBmdbsQQARW2mwtunGiwPISF5l--