From nobody Mon Apr 29 00:34:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487320190236752.6385354066807; Fri, 17 Feb 2017 00:29:50 -0800 (PST) Received: from localhost ([::1]:52090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cedvI-0003Ko-Q4 for importer@patchew.org; Fri, 17 Feb 2017 03:29:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cedtg-0002Y4-KS for qemu-devel@nongnu.org; Fri, 17 Feb 2017 03:28:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cedtb-0000EZ-Mo for qemu-devel@nongnu.org; Fri, 17 Feb 2017 03:28:08 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:35866) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cedtb-0000E3-HP for qemu-devel@nongnu.org; Fri, 17 Feb 2017 03:28:03 -0500 Received: by mail-pg0-x244.google.com with SMTP id a123so1590984pgc.3 for ; Fri, 17 Feb 2017 00:28:03 -0800 (PST) Received: from localhost.localdomain (v133-130-103-189.a02c.g.tyo1.static.cnode.io. [133.130.103.189]) by smtp.gmail.com with ESMTPSA id r74sm17819361pfb.67.2017.02.17.00.27.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 00:28:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dciRhJPUkemRiByEje8cmUk8CT7F7HyK0vVDD0Nao4U=; b=gNOAjf0VkWitZT+rz+9Mv0JpcB/7qci8bdsTFNtwo2HFFhjjuO+w92S78/8yJ6kNxJ r0GXVfDFna/kNH6zeQZDLqg98dwFXSFM1MciTFPz6Z4/sWzoMK8o0tkan9FtsJT2piiZ H4pnqibcz74GEySDEVv170Pr64Puuwld1jnPP0K0sFJScZXlwhfpFb3rtDriTtAzKsfZ ODJ4HsSfgBQYtVlnBRSIAixhei7YxEyw11yITzLLufUKfCKGvP3P5YfCyOa979KnfBLB apfM6/xzPoL2PsQjA5hQaCimzSQJtloG+F7+RSSH0Wu6TM/06Co5XE4/VLpqWMs3sWsC envQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dciRhJPUkemRiByEje8cmUk8CT7F7HyK0vVDD0Nao4U=; b=leBidYTdUV7mXJpfjCU5HZVngwMkJ9CmgYp2SXzt2IQf7Jg2yTh0YQMxtRto/KJ4so BI3hixsbH4Z2WSFypKaURZ8WJXaSLY6J48Wxu3EZ4WGORB6QP/QpJblj2tPFTBvQ8nK9 zwAJi5r0qwYVRlnwq8Lc16nWAKkxNFdavaAaWZBS12t653iHIRGdaEPjlYSM5PUhiwze 6EMUP1/s4EWVwAoWABePYj84czi0KtWq5dmpQ3cbFjCTaMBSINPHfEORRH3bonVCKWoE zuDY/SP9DlOteLYqtPiCzwmMbTn8ixH3Llvh7dqPAFAiw3RVZE2IR76pBYCfWoykxS5j Rm3A== X-Gm-Message-State: AMke39nu5dyg9Y8HesWaQ0E8UElwxRLpwpiHW3/XaBEK8U9Q+6lKoG3WtHQ8FsQO56qekA== X-Received: by 10.98.10.69 with SMTP id s66mr7916788pfi.146.1487320082557; Fri, 17 Feb 2017 00:28:02 -0800 (PST) From: Ziyue Yang To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 16:27:03 +0800 Message-Id: <20170217082704.23270-2-skiver.cloud.yzy@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170217082704.23270-1-skiver.cloud.yzy@gmail.com> References: <20170217082704.23270-1-skiver.cloud.yzy@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH 1/2] monitor.c: make mon_get_cpu return NULL when there is no CPU X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ziyue Yang , Ziyue Yang , "Dr . David Alan Gilbert" , Pavel Butsykin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ziyue Yang Currently mon_get_cpu always dereferences first_cpu without checking whether it's a valid pointer. This commit adds check before dereferencing, and reports "No CPU" info if there isn't any CPU then returns NULL. Signed-off-by: Ziyue Yang Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- monitor.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/monitor.c b/monitor.c index 3cd72a9bab..6b25cf7a2b 100644 --- a/monitor.c +++ b/monitor.c @@ -1026,6 +1026,10 @@ int monitor_set_cpu(int cpu_index) CPUState *mon_get_cpu(void) { if (!cur_mon->mon_cpu) { + if (!first_cpu) { + monitor_printf(cur_mon, "No CPU available on this machine\n"); + return NULL; + } monitor_set_cpu(first_cpu->cpu_index); } cpu_synchronize_state(cur_mon->mon_cpu); @@ -2495,11 +2499,11 @@ static int default_fmt_size =3D 4; static int is_valid_option(const char *c, const char *typestr) { char option[3]; - =20 + option[0] =3D '-'; option[1] =3D *c; option[2] =3D '\0'; - =20 + typestr =3D strstr(typestr, option); return (typestr !=3D NULL); } @@ -2864,7 +2868,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, p++; if(c !=3D *p) { if(!is_valid_option(p, typestr)) { - =20 + monitor_printf(mon, "%s: unsupported option -%= c\n", cmd->name, *p); goto fail; --=20 2.11.0 From nobody Mon Apr 29 00:34:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487320209010652.2618962216278; Fri, 17 Feb 2017 00:30:09 -0800 (PST) Received: from localhost ([::1]:52093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cedvZ-0003bF-Uw for importer@patchew.org; Fri, 17 Feb 2017 03:30:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cedtr-0002fB-Qc for qemu-devel@nongnu.org; Fri, 17 Feb 2017 03:28:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cedtm-0000M0-Su for qemu-devel@nongnu.org; Fri, 17 Feb 2017 03:28:19 -0500 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:33425) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cedtm-0000L9-JA for qemu-devel@nongnu.org; Fri, 17 Feb 2017 03:28:14 -0500 Received: by mail-pf0-x244.google.com with SMTP id e4so3611766pfg.0 for ; Fri, 17 Feb 2017 00:28:14 -0800 (PST) Received: from localhost.localdomain (v133-130-103-189.a02c.g.tyo1.static.cnode.io. [133.130.103.189]) by smtp.gmail.com with ESMTPSA id r74sm17819361pfb.67.2017.02.17.00.28.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 00:28:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3lwYUi+tew54WZg1BLaZjxHbTi1KbuqNZCn68PGlvw4=; b=Z2xN/CYhCa9zjoCv5xxWYcuydXgMWGMOhGy6JkISfxQk4hgH5pikl4DE4flTtz9T+9 bcKV3/6dF1zGXGhI9CX5byHm6qwzHFQo7JX+AsysScpeA+cgkdW4wO5v+jol7n1lyuxv PzgSN1QnJReEpskJ1aFYZIyn3mMeWNu6qIK6WIcLOwqydkxL50h0YJdmKhGuD6tXv3lD aYdOpIVuj1qcWLtpwwZy7jNaAxrtbJltOHiykeQeJSpG17AS5mXL5U1sRfhJDS3WvaA+ TaT5ccRIw9Ac+3X5YpMVm0HArY02CumYM9nllCEbu2IFDnqGSjkTQaSQYdn7pdVLgXd+ c2LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3lwYUi+tew54WZg1BLaZjxHbTi1KbuqNZCn68PGlvw4=; b=R/Kn6TrpXAtH244eeyylpx8hlCLrtVa9GDkBqij5bzRfnL5UiUtlBTfKqNxYzp1r+9 gmiar7yrLgVsrfx2XY7ejYjQ55+qHf+l/QdOlMxbGO3DER7twtIMPuJ41I4j8f2I5PMl rM0PqFj5RwLBlbr7SveOYKfTWkvkVFsL7PIEcC/X3aWg/aid1Io80Bd3gALfz2hTykUI HTUoJQ4Y2EwNYiCHe5QDLnDrsz1rhUTtjPiuH8je3GyORZbThXcdfVsfuZ87gE7h6E5D tKalWs7Q1+b4RAzDi88bThITk2cCwLYTznDNy8bnjSOFaEfqGs+ele0qM10WC5d96ghO gDXQ== X-Gm-Message-State: AMke39m0QFATfMFZkBR+IULuHrY31leOvkDiEydlzgfGbI0GaoUV/ZdIFAyHjH58mR/xXg== X-Received: by 10.84.195.1 with SMTP id i1mr9353615pld.77.1487320093579; Fri, 17 Feb 2017 00:28:13 -0800 (PST) From: Ziyue Yang To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 16:27:04 +0800 Message-Id: <20170217082704.23270-3-skiver.cloud.yzy@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170217082704.23270-1-skiver.cloud.yzy@gmail.com> References: <20170217082704.23270-1-skiver.cloud.yzy@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH 2/2] target/i386/monitor.c: check return value of mon_get_cpu before using it X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ziyue Yang , Ziyue Yang , "Dr . David Alan Gilbert" , Pavel Butsykin Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ziyue Yang This patch eliminates the segfault caused by accessing CPU that doesn't exist in hmp command "info lapic", which can be reproduced by $ qemu-system-x86_64 -nographic -M none -serial none -monitor stdio and then type "info lapic" into qemu monitor. Signed-off-by: Ziyue Yang Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/i386/monitor.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/target/i386/monitor.c b/target/i386/monitor.c index 468aa073bc..7b96c74a24 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -624,8 +624,11 @@ const MonitorDef *target_monitor_defs(void) =20 void hmp_info_local_apic(Monitor *mon, const QDict *qdict) { - x86_cpu_dump_local_apic_state(mon_get_cpu(), (FILE *)mon, monitor_fpri= ntf, - CPU_DUMP_FPU); + CPUState *cs =3D mon_get_cpu(); + if (cs) { + x86_cpu_dump_local_apic_state(cs, (FILE *)mon, monitor_fprintf, + CPU_DUMP_FPU); + } } =20 void hmp_info_io_apic(Monitor *mon, const QDict *qdict) --=20 2.11.0