From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbZlC-000085-Lb for qemu-devel@nongnu.org; Mon, 04 Jun 2012 12:04:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbZl8-0006Vj-00 for qemu-devel@nongnu.org; Mon, 04 Jun 2012 12:04:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41172) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbZl7-0006VM-NU for qemu-devel@nongnu.org; Mon, 04 Jun 2012 12:03:57 -0400 Message-ID: <4FCCDC55.5070705@redhat.com> Date: Mon, 04 Jun 2012 10:03:33 -0600 From: Eric Blake MIME-Version: 1.0 References: <1338815410-24890-1-git-send-email-coreyb@linux.vnet.ibm.com> <1338815410-24890-3-git-send-email-coreyb@linux.vnet.ibm.com> <4FCCC6F8.3010901@redhat.com> <4FCCD987.8080205@linux.vnet.ibm.com> In-Reply-To: <4FCCD987.8080205@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig8471F8D603981F33709D73B9" Subject: Re: [Qemu-devel] [PATCH 2/3] block: Add support to "open" /dev/fd/X filenames List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Bryant Cc: kwolf@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig8471F8D603981F33709D73B9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/04/2012 09:51 AM, Corey Bryant wrote: >>> + >>> + if (strstart(filename, "/dev/fd/",&p)) { >>> + fd =3D atoi(p); >> >> atoi() is lousy - it has no error checking, and returns 0 if a mistake= >> was made. You really want to be using strtol (or even better, a >> sensible wrapper around strtol that takes care of the subtleties of >> calling it correctly), so that you don't end up dup'ing stdin when the= >> user passes a bad /dev/fd/ string. >> >=20 > It looks like strtol returns 0 on failure too. Do we need to support > stdin/stdout/stderr? But at least strtol lets you detect errors: char *tmp; errno =3D 0; fd =3D strtol(p, &tmp, 10); if (errno || tmp =3D=3D p) { /* raise your error here */ } and if you get past that point, then someone really did pass in /dev/fd/0 as the string they meant to be parsed (probably a user bug, as getfd is unlikely to ever return 0 unless you start with stdin closed, which itself is something that POSIX discourages, but not something we need to specifically worry about). So I would argue that yes, we do need to support fd 0, if only by not special casing it as compared to any other valid fd. --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig8471F8D603981F33709D73B9 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/ iQEcBAEBCAAGBQJPzNxXAAoJEKeha0olJ0NqGPkIAJCfZzOTZhd5/nlNentocmep g8DzTWn0zXxXdrbm1+p6u96t2wc1DLBH/3HEzy+DxIB7ZZY5TBywrzymIZKkgV+w TVdMi1BucBw0MJZjgqy3c8BLuVcpk4pkuBCCatu9peETmhwQmoZ3RM0VuMU+h+3c AaE1pe+CgNxXHA6TysQd4q6Ght79y8dlfrg5UnkSc6CO4rZU2XyqQsOEwvvru6ON y5Sz01REfutIvFV5CRKXxgNVyQLQtreZuPlOilF7lNML3u13D3NrZFz+Kkcuz6Vy ReCLUroZgwgouv/CMO/tqV4rDLoed6ZozdXK5M2WrpPIgv6xyXpKFKmFq7xDeH8= =E/1V -----END PGP SIGNATURE----- --------------enig8471F8D603981F33709D73B9--