summary refs log tree commit diff stats
path: root/qemu-ga.c
diff options
context:
space:
mode:
authorMichael Roth <mdroth@linux.vnet.ibm.com>2012-05-14 16:42:35 -0500
committerMichael Roth <mdroth@linux.vnet.ibm.com>2012-05-15 09:16:55 -0500
commit6c615ec57e83bf8cc7b1721bcd58c7d1ed93ef65 (patch)
tree7f3984ee87168ce88de2c66b330c5bdd639febef /qemu-ga.c
parent3674838cd05268954bb6473239cd7f700a79bf0f (diff)
downloadfocaccia-qemu-6c615ec57e83bf8cc7b1721bcd58c7d1ed93ef65.tar.gz
focaccia-qemu-6c615ec57e83bf8cc7b1721bcd58c7d1ed93ef65.zip
qemu-ga: fix segv after failure to open log file
Currently, if we fail to open the specified log file (generally due to a
permissions issue), we'll assign NULL to the logfile handle (stderr,
initially) used by the logging routines, which can cause a segfault to
occur when we attempt to report the error before exiting.

Instead, only re-assign if the open() was successful.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qemu-ga.c')
-rw-r--r--qemu-ga.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/qemu-ga.c b/qemu-ga.c
index 3a88333a17..42e271f35f 100644
--- a/qemu-ga.c
+++ b/qemu-ga.c
@@ -836,12 +836,13 @@ int main(int argc, char **argv)
             become_daemon(pid_filepath);
         }
         if (log_filepath) {
-            s->log_file = fopen(log_filepath, "a");
-            if (!s->log_file) {
+            FILE *log_file = fopen(log_filepath, "a");
+            if (!log_file) {
                 g_critical("unable to open specified log file: %s",
                            strerror(errno));
                 goto out_bad;
             }
+            s->log_file = log_file;
         }
     }