From: Peter Maydell <peter.maydell@linaro.org>
To: Michael Roth <mdroth@linux.vnet.ibm.com>
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, lcapitulino@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1.1] qemu-ga: fix segv after failure to open log file
Date: Tue, 15 May 2012 14:32:41 +0100 [thread overview]
Message-ID: <CAFEAcA-Z=JWcW8-RvxJGo601AFWRr2RLLLSPqOdp1MMEfrCYPQ@mail.gmail.com> (raw)
In-Reply-To: <1337033057-31707-1-git-send-email-mdroth@linux.vnet.ibm.com>
On 14 May 2012 23:04, Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
> 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;
> }
> }
It would be nicer to put the log_file variable definition
inside the if(), rather than putting it 150 lines earlier
in the source file...
-- PMM
next prev parent reply other threads:[~2012-05-15 13:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2012-05-15 14:22 ` Michael Roth
2012-05-15 14:36 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFEAcA-Z=JWcW8-RvxJGo601AFWRr2RLLLSPqOdp1MMEfrCYPQ@mail.gmail.com' \
--to=peter.maydell@linaro.org \
--cc=aliguori@us.ibm.com \
--cc=lcapitulino@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).