Patchwork [v2,2/2] qga: unlink just created guest-file if fchmod() or fdopen() fails on it

login
register
mail settings
Submitter Laszlo Ersek
Date May 8, 2013, 3:31 p.m.
Message ID <1368027096-12108-3-git-send-email-lersek@redhat.com>
Download mbox | patch
Permalink /patch/242600/
State New
Headers show

Comments

Laszlo Ersek - May 8, 2013, 3:31 p.m.
We shouldn't allow guest filesystem pollution on error paths.

Suggested-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 qga/commands-posix.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Eric Blake - May 8, 2013, 5:07 p.m.
On 05/08/2013 09:31 AM, Laszlo Ersek wrote:
> We shouldn't allow guest filesystem pollution on error paths.
> 
> Suggested-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  qga/commands-posix.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 2eec712..e199738 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -355,6 +355,9 @@ safe_open_or_create(const char *path, const char *mode, Error **err)
>              }
>  
>              close(fd);
> +            if (oflag & O_CREAT) {
> +                unlink(path);
> +            }
>          }
>      }
>  
>

Patch

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 2eec712..e199738 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -355,6 +355,9 @@  safe_open_or_create(const char *path, const char *mode, Error **err)
             }
 
             close(fd);
+            if (oflag & O_CREAT) {
+                unlink(path);
+            }
         }
     }