From nobody Sat May 18 19:47:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1579742983; cv=none; d=zohomail.com; s=zohoarc; b=VC6cmQmveqtE7DPAp/sMiarRhGPQSnSgrY9ARYMaLv70FCqopTKrY4lJrU/04lW0alAr3ErZxC/GHLMGW+Swd2iarK6OyhJg8dRZHeao0uqei4Q2IWv2d/i3eUGA8OAHt+ovMCU7IklMwy4/MKAud4aIYTOw9quDZhWy+e3WwVE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579742983; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=cUWhZT2R1dCpEqjpaeYlV4E1qXSlViH2gDDTH6Sn7Vc=; b=YGFLVXxf9rGvSD6WcBMlmWMEK96ct8V4gyTk7wjYKLbnlsKXnRBekm8PztpNm4MRt+vuH6J9Dpm82/MG3mNyKwNmQe54Ev2HVqZPlYAoz0P+kxCymzXSJNzfK8MDTfTah01EkkrtYM+qfcHDm0hrHSgU7V+/XrSjQR5FNneuL7k= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579742983770122.13717852749801; Wed, 22 Jan 2020 17:29:43 -0800 (PST) Received: from localhost ([::1]:49736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuRJW-000278-8C for importer@patchew.org; Wed, 22 Jan 2020 20:29:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60254) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuNNm-00041V-Vs for qemu-devel@nongnu.org; Wed, 22 Jan 2020 16:17:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuNNl-0007FU-SB for qemu-devel@nongnu.org; Wed, 22 Jan 2020 16:17:50 -0500 Received: from smtp.qindel.com ([89.140.90.34]:45952 helo=thor.qindel.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iuNNl-0007Cc-Mb; Wed, 22 Jan 2020 16:17:49 -0500 Received: from localhost (localhost [127.0.0.1]) by thor.qindel.com (Postfix) with ESMTP id 106FD601FF; Wed, 22 Jan 2020 22:08:15 +0100 (CET) Received: from thor.qindel.com ([127.0.0.1]) by localhost (thor.qindel.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id D-EQ8sW2gTWe; Wed, 22 Jan 2020 22:08:14 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by thor.qindel.com (Postfix) with ESMTP id D634260214; Wed, 22 Jan 2020 22:08:14 +0100 (CET) Received: from thor.qindel.com ([127.0.0.1]) by localhost (thor.qindel.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XMXxiAbV2CnJ; Wed, 22 Jan 2020 22:08:14 +0100 (CET) Received: from freeso.my.domain (unknown [82.213.225.96]) by thor.qindel.com (Postfix) with ESMTPSA id 69593601FF; Wed, 22 Jan 2020 22:08:14 +0100 (CET) X-Virus-Scanned: amavisd-new at thor.qindel.com 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 22:08:12 +0100 Message-Id: <20200122210812.17124-1-salvador@qindel.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 89.140.90.34 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 =3D NULL; =20 - pidstr =3D strstr(filename, "%"); - if (pidstr) { - /* We only accept one %d, no other format strings */ - if (pidstr[1] !=3D 'd' || strchr(pidstr + 2, '%')) { - error_setg(errp, "Bad logfile format: %s", filename); - return; - } else { - logfilename =3D g_strdup_printf(filename, getpid()); - } - } else { - logfilename =3D g_strdup(filename); + if (filename) { + char *pidstr =3D strstr(filename, "%"); + if (pidstr) { + /* We only accept one %d, no other format strings */ + if (pidstr[1] !=3D 'd' || strchr(pidstr + 2, '%')) { + error_setg(errp, "Bad logfile format: %s", filename); + return; + } else { + logfilename =3D g_strdup_printf(filename, getpid()); + } + } else { + logfilename =3D g_strdup(filename); + } } + /* else, let logfilename be NULL indicating we want to use stderr */ + qemu_log_close(); qemu_set_log(qemu_loglevel); } --=20 2.24.1