From: Ziyue Yang <skiver.cloud.yzy@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Pavel Butsykin <pbutsykin@virtuozzo.com>,
Ziyue Yang <yzylivezh@hotmail.com>,
Ziyue Yang <skiver.cloud.yzy@gmail.com>
Subject: [Qemu-devel] [PATCH 1/2] monitor.c: make mon_get_cpu return NULL when there is no CPU
Date: Fri, 17 Feb 2017 16:27:03 +0800 [thread overview]
Message-ID: <20170217082704.23270-2-skiver.cloud.yzy@gmail.com> (raw)
In-Reply-To: <20170217082704.23270-1-skiver.cloud.yzy@gmail.com>
From: Ziyue Yang <yzylivezh@hotmail.com>
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 <skiver.cloud.yzy@gmail.com>
---
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 = 4;
static int is_valid_option(const char *c, const char *typestr)
{
char option[3];
-
+
option[0] = '-';
option[1] = *c;
option[2] = '\0';
-
+
typestr = strstr(typestr, option);
return (typestr != NULL);
}
@@ -2864,7 +2868,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
p++;
if(c != *p) {
if(!is_valid_option(p, typestr)) {
-
+
monitor_printf(mon, "%s: unsupported option -%c\n",
cmd->name, *p);
goto fail;
--
2.11.0
next prev parent reply other threads:[~2017-02-17 8:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-17 8:27 [Qemu-devel] [PATCH 0/2] fix segfaults caused by accessing CPU in empty machine Ziyue Yang
2017-02-17 8:27 ` Ziyue Yang [this message]
2017-02-19 3:55 ` [Qemu-devel] [PATCH 1/2] monitor.c: make mon_get_cpu return NULL when there is no CPU Philippe Mathieu-Daudé
2017-02-20 6:09 ` Thomas Huth
2017-02-20 9:33 ` Yang Ziyue
2017-02-17 8:27 ` [Qemu-devel] [PATCH 2/2] target/i386/monitor.c: check return value of mon_get_cpu before using it Ziyue Yang
2017-02-19 3:56 ` Philippe Mathieu-Daudé
2017-02-20 6:07 ` [Qemu-devel] [PATCH 0/2] fix segfaults caused by accessing CPU in empty machine Thomas Huth
2017-02-21 19:42 ` Dr. David Alan Gilbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170217082704.23270-2-skiver.cloud.yzy@gmail.com \
--to=skiver.cloud.yzy@gmail.com \
--cc=dgilbert@redhat.com \
--cc=pbutsykin@virtuozzo.com \
--cc=qemu-devel@nongnu.org \
--cc=yzylivezh@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).