qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1.1] qemu-ga: fix segv after failure to open log file
@ 2012-05-14 22:04 Michael Roth
  2012-05-15  8:07 ` Michal Privoznik
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Michael Roth @ 2012-05-14 22:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori, lcapitulino

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.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qemu-ga.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/qemu-ga.c b/qemu-ga.c
index 3a88333..e2725c8 100644
--- a/qemu-ga.c
+++ b/qemu-ga.c
@@ -681,6 +681,7 @@ int main(int argc, char **argv)
     const char *log_filepath = NULL;
     const char *pid_filepath = QGA_PIDFILE_DEFAULT;
     const char *state_dir = QGA_STATEDIR_DEFAULT;
+    FILE *log_file;
 #ifdef _WIN32
     const char *service = NULL;
 #endif
@@ -836,12 +837,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) {
+            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;
         }
     }
 
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-05-15 16:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14 22:04 [Qemu-devel] [PATCH 1.1] qemu-ga: fix segv after failure to open log file Michael Roth
2012-05-15  8:07 ` Michal Privoznik
2012-05-15 13:04 ` Luiz Capitulino
2012-05-15 14:14   ` Michael Roth
2012-05-15 14:46     ` Luiz Capitulino
2012-05-15 13:32 ` Peter Maydell
2012-05-15 14:22   ` Michael Roth
2012-05-15 14:36     ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).