From patchwork Wed Jan 22 20:21:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Salvador_Fandi=C3=B1o?= X-Patchwork-Id: 1227570 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=qindel.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4834Rx6SgJz9sRk for ; Thu, 23 Jan 2020 12:29:01 +1100 (AEDT) Received: from localhost ([::1]:49732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuRIp-0000xR-43 for incoming@patchwork.ozlabs.org; Wed, 22 Jan 2020 20:28:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59607) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuNKM-0001dA-Hx for qemu-devel@nongnu.org; Wed, 22 Jan 2020 16:14:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuNKL-0004Nu-2d for qemu-devel@nongnu.org; Wed, 22 Jan 2020 16:14:18 -0500 Received: from static.96.225.213.82.ibercom.com ([82.213.225.96]:52942 helo=freeso) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iuNKK-0004Jq-RS; Wed, 22 Jan 2020 16:14:17 -0500 Received: from freeso (localhost [127.0.0.1]) by freeso (8.15.2/8.15.2) with ESMTPS id 00MKLQVO017038 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 22 Jan 2020 21:21:26 +0100 (CET) (envelope-from salva@freeso) Received: (from salva@localhost) by freeso (8.15.2/8.15.2/Submit) id 00MKLQWU017037; Wed, 22 Jan 2020 21:21:26 +0100 (CET) (envelope-from salva) From: salvador@qindel.com To: qemu-devel@nongnu.org Subject: [PATCH] qemu_set_log_filename: filename argument may be NULL Date: Wed, 22 Jan 2020 21:21:25 +0100 Message-Id: <20200122202125.16993-1-salvador@qindel.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 82.213.225.96 X-Mailman-Approved-At: Wed, 22 Jan 2020 20:28:29 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, sfandino@yahoo.com, Salvador Fandino Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Salvador Fandino 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 --- 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); }