diff options
author | Salvador Fandino <salvador@qindel.com> | 2020-01-23 20:36:26 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2020-01-30 21:33:50 +0000 |
commit | e144a605a614d22165000c69e8e1dc6986d45cd8 (patch) | |
tree | 28a01420e1a82b85f248518c109d418176521903 /util/log.c | |
parent | d4aceb2eb78a5f15e94791a43732c24b52c35dc5 (diff) |
qemu_set_log_filename: filename argument may be NULL
NULL is a valid log filename used to indicate we want to use stderr
but qemu_set_log_filename (which is called by bsd-user/main.c) was not
handling it correctly.
That also made redundant a couple of NULL checks in calling code which
have been removed.
Signed-off-by: Salvador Fandino <salvador@qindel.com>
Message-Id: <20200123193626.19956-1-salvador@qindel.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'util/log.c')
-rw-r--r-- | util/log.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/util/log.c b/util/log.c index 867264da8d..47f2827397 100644 --- a/util/log.c +++ b/util/log.c @@ -148,25 +148,29 @@ void qemu_log_needs_buffers(void) * Allow the user to include %d in their logfile which will be * substituted with the current PID. This is useful for debugging many * nested linux-user tasks but will result in lots of logs. + * + * filename may be NULL. In that case, log output is sent to stderr */ void qemu_set_log_filename(const char *filename, Error **errp) { - char *pidstr; g_free(logfilename); logfilename = NULL; - pidstr = strstr(filename, "%"); - if (pidstr) { - /* We only accept one %d, no other format strings */ - if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) { - error_setg(errp, "Bad logfile format: %s", filename); - return; - } else { - logfilename = g_strdup_printf(filename, getpid()); - } - } else { - logfilename = g_strdup(filename); + if (filename) { + char *pidstr = strstr(filename, "%"); + if (pidstr) { + /* We only accept one %d, no other format strings */ + if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) { + error_setg(errp, "Bad logfile format: %s", filename); + return; + } else { + logfilename = g_strdup_printf(filename, getpid()); + } + } else { + logfilename = g_strdup(filename); + } } + qemu_log_close(); qemu_set_log(qemu_loglevel); } |