qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/2] qga: try to unlink just created guest-file


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 2/2] qga: try to unlink just created guest-file if fchmod() fails on it
Date: Tue, 07 May 2013 11:30:10 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130402 Thunderbird/17.0.5

On 05/07/2013 10:56 AM, Laszlo Ersek wrote:
> We shouldn't allow guest filesystem pollution on error paths.
> 
> Suggested-by: Eric Blake <address@hidden>
> Signed-off-by: Laszlo Ersek <address@hidden>
> ---
>  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 - 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);
+           }
         }
     }

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]