[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] qemu_set_log_filename: filename argument may be NULL
From: |
salvador |
Subject: |
[PATCH] qemu_set_log_filename: filename argument may be NULL |
Date: |
Wed, 22 Jan 2020 22:08:12 +0100 |
From: Salvador Fandino <address@hidden>
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.
Signed-off-by: Salvador Fandino <address@hidden>
---
util/log.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/util/log.c b/util/log.c
index 867264da8d..3cd2ebfdf4 100644
--- a/util/log.c
+++ b/util/log.c
@@ -151,22 +151,25 @@ void qemu_log_needs_buffers(void)
*/
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);
+ }
}
+ /* else, let logfilename be NULL indicating we want to use stderr */
+
qemu_log_close();
qemu_set_log(qemu_loglevel);
}
--
2.24.1
- [PATCH] qemu_set_log_filename: filename argument may be NULL,
salvador <=