From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZsK0-0002IQ-BE for qemu-devel@nongnu.org; Tue, 07 May 2013 20:33:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZsJw-0007X7-Gs for qemu-devel@nongnu.org; Tue, 07 May 2013 20:33:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1479) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZsJw-0007X3-80 for qemu-devel@nongnu.org; Tue, 07 May 2013 20:33:24 -0400 Message-ID: <51899DDC.3060101@redhat.com> Date: Wed, 08 May 2013 02:35:40 +0200 From: Laszlo Ersek MIME-Version: 1.0 References: <518923DA.6030105@redhat.com> <1367945808-19979-2-git-send-email-lersek@redhat.com> <51893A22.1040105@redhat.com> In-Reply-To: <51893A22.1040105@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: Eric Blake Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On 05/07/13 19:30, Eric Blake wrote: > On 05/07/2013 10:56 AM, Laszlo Ersek wrote: >> We shouldn't allow guest filesystem pollution on error paths. >> >> Suggested-by: Eric Blake >> Signed-off-by: Laszlo Ersek >> --- >> qga/commands-posix.c | 1 + >> 1 files changed, 1 insertions(+), 0 deletions(-) >> >> 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 *mode, Error **err) >> error_setg_errno(&local_err, errno, "failed to set permission " >> "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 Please provide a reference for "not required by POSIX". The EBUSY condition I'm looking at says "The file named by the path argument cannot be unlinked because it is being used by the system or another process and the implementation considers this an error". "Used by the system or another process" shouldn't really be the case here. - 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); > + } > } > } > I'll give myself some time on this. Clearly if I rush a patch I make a mess. Thanks, Laszlo