Skip to content

Commit

Permalink
qemu-ga: fix segv after failure to open log file
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mdroth committed May 15, 2012
1 parent 3674838 commit 6c615ec
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions qemu-ga.c
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 6c615ec

Please sign in to comment.