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

login
register
mail settings
Submitter Michael Roth
Date May 14, 2013, 9:53 p.m.
Message ID <1368568392-2127-16-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/243848/
State New
Headers show

Comments

Michael Roth - May 14, 2013, 9:53 p.m.
From: Laszlo Ersek <lersek@redhat.com>

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>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
(cherry picked from commit 2b720018060179b394f8ce736983373ab80dd37c)

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/commands-posix.c |    3 +++
 1 file changed, 3 insertions(+)

Patch

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