From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:53086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUJ4T-0001JF-2L for qemu-devel@nongnu.org; Tue, 15 May 2012 10:49:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SUJ4Q-00034P-T3 for qemu-devel@nongnu.org; Tue, 15 May 2012 10:49:52 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:37715) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUJ4Q-0002w4-La for qemu-devel@nongnu.org; Tue, 15 May 2012 10:49:50 -0400 Received: by mail-ob0-f173.google.com with SMTP id wd20so11016863obb.4 for ; Tue, 15 May 2012 07:49:49 -0700 (PDT) Sender: fluxion From: Michael Roth Date: Tue, 15 May 2012 09:48:58 -0500 Message-Id: <1337093339-10786-13-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1337093339-10786-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1337093339-10786-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 12/13] qemu-ga: fix segv after failure to open log file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mprivozn@redhat.com, aliguori@us.ibm.com, eblake@redhat.com, jcody@redhat.com, lcapitulino@redhat.com 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 Signed-off-by: Michael Roth --- qemu-ga.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/qemu-ga.c b/qemu-ga.c index 3a88333..42e271f 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; } } -- 1.7.4.1