From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZm7p-0003cD-Rq for qemu-devel@nongnu.org; Tue, 07 May 2013 13:56:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZm7o-00047e-F0 for qemu-devel@nongnu.org; Tue, 07 May 2013 13:56:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZm7o-00047Z-6t for qemu-devel@nongnu.org; Tue, 07 May 2013 13:56:28 -0400 Message-ID: <51893A22.1040105@redhat.com> Date: Tue, 07 May 2013 11:30:10 -0600 From: Eric Blake MIME-Version: 1.0 References: <518923DA.6030105@redhat.com> <1367945808-19979-2-git-send-email-lersek@redhat.com> In-Reply-To: <1367945808-19979-2-git-send-email-lersek@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2TIMRMWQTUITKANKLHBMK" Subject: Re: [Qemu-devel] [PATCH 2/2] qga: try to unlink just created guest-file if fchmod() fails on it List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laszlo Ersek Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2TIMRMWQTUITKANKLHBMK Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 05/07/2013 10:56 AM, Laszlo Ersek wrote: > We shouldn't allow guest filesystem pollution on error paths. >=20 > Suggested-by: Eric Blake > Signed-off-by: Laszlo Ersek > --- > qga/commands-posix.c | 1 + > 1 files changed, 1 insertions(+), 0 deletions(-) >=20 > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > index 2eec712..d301b1f 100644 > --- a/qga/commands-posix.c > +++ b/qga/commands-posix.c > @@ -341,6 +341,7 @@ safe_open_or_create(const char *path, const char *m= ode, Error **err) > error_setg_errno(&local_err, errno, "failed to set per= mission " > "0%03o on new file '%s' (mode: '%s')"= , > (unsigned)DEFAULT_NEW_FILE_MODE, path= , mode); > + unlink(path); This fixes the case of a mode 0000 file if fchmod fails, but doesn't fix the case of a mode 0666 file if fchmod succeeds but fdopen fails. It also requires that unlink() while open works (true for most Unix systems, but false for Windows systems and not required by POSIX - but see my realization on 1/2 that this file isn't compiled on Windows). I think you want this instead: diff --git i/qga/commands-posix.c w/qga/commands-posix.c index 04c6951..89cc6d8 100644 --- i/qga/commands-posix.c +++ w/qga/commands-posix.c @@ -345,6 +345,9 @@ safe_open_or_create(const char *path, const char *mode, Error **err) } close(fd); + if (oflag & O_CREAT) { + unlink(path); + } } } --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2TIMRMWQTUITKANKLHBMK 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.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJRiToiAAoJEKeha0olJ0NqL8UH/R9Ki66mNjxQMv75Qh9Whzbm ZeHZU3ltQPEaBXc6ALQ67RYnH5yUtAvhu9kxvBJ0fzYpIgXhLbzuo4ijFSrnQpsD bCGs6BB86Np88Nj/IQ3h8Duq/1MHdFPfiWLTt9L12Ju1G0mZlJoeKHRRWeGqvpFq TWf362WV8CSpsBR+5oqwflHYatKYudQ7ciW7D7M9VJq+KFkVr8WW+7n0cCKJI9Gx APytxpXf+QuJJs/z1R4ValNhbIgrV4wq0IoTMFCsiHC1jg6Djg/7VEMANb8UMFBs WAMz7TvXVY4vAnvpe1Xa3K0orDDj+60KxqYo8HT/TOcCaJIGTVBZnXBmlhZEZd8= =6s9c -----END PGP SIGNATURE----- ------enig2TIMRMWQTUITKANKLHBMK--