Commit e144a605 authored by Salvador Fandino's avatar Salvador Fandino Committed by Stefan Hajnoczi
Browse files

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: default avatarSalvador Fandino <salvador@qindel.com>
Message-Id: <20200123193626.19956-1-salvador@qindel.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent d4aceb2e
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -229,9 +229,7 @@ void trace_init_file(const char *file)
    /* If both the simple and the log backends are enabled, "--trace file"
     * only applies to the simple backend; use "-D" for the log backend.
     */
    if (file) {
    qemu_set_log_filename(file, &error_fatal);
    }
#else
    if (file) {
        fprintf(stderr, "error: --trace file=...: "
+16 −12
Original line number Diff line number Diff line
@@ -148,14 +148,16 @@ 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 (filename) {
            char *pidstr = strstr(filename, "%");
            if (pidstr) {
                /* We only accept one %d, no other format strings */
                if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) {
@@ -167,6 +169,8 @@ void qemu_set_log_filename(const char *filename, Error **errp)
            } else {
                logfilename = g_strdup(filename);
            }
    }

    qemu_log_close();
    qemu_set_log(qemu_loglevel);
}
+1 −4
Original line number Diff line number Diff line
@@ -3903,10 +3903,7 @@ int main(int argc, char **argv, char **envp)

    /* Open the logfile at this point and set the log mask if necessary.
     */
    if (log_file) {
    qemu_set_log_filename(log_file, &error_fatal);
    }

    if (log_mask) {
        int mask;
        mask = qemu_str_to_log_mask(log_mask);