summaryrefslogtreecommitdiff
path: root/hmp.c
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2017-01-13 13:12:35 +0100
committerDr. David Alan Gilbert <dgilbert@redhat.com>2017-02-21 18:29:01 +0000
commit854e67fea6a6f181163a5467fc9ba04de8d181bb (patch)
tree95528d10774a6b5021083310dee65c7bbe376274 /hmp.c
parent5fc00480ab1ce767f1c6c63ae644e960295fed2c (diff)
downloadqemu-854e67fea6a6f181163a5467fc9ba04de8d181bb.tar.gz
monitor: Fix crashes when using HMP commands without CPU
When running certain HMP commands ("info registers", "info cpustats", "info tlb", "nmi", "memsave" or dumping virtual memory) with the "none" machine, QEMU crashes with a segmentation fault. This happens because the "none" machine does not have any CPUs by default, but these HMP commands did not check for a valid CPU pointer yet. Add such checks now, so we get an error message about the missing CPU instead. Signed-off-by: Thomas Huth <thuth@redhat.com> Message-Id: <1484309555-1935-1-git-send-email-thuth@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Acked-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'hmp.c')
-rw-r--r--hmp.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/hmp.c b/hmp.c
index 8b0c2b072f..aba728f0de 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1014,8 +1014,14 @@ void hmp_memsave(Monitor *mon, const QDict *qdict)
const char *filename = qdict_get_str(qdict, "filename");
uint64_t addr = qdict_get_int(qdict, "val");
Error *err = NULL;
+ int cpu_index = monitor_get_cpu_index();
- qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
+ if (cpu_index < 0) {
+ monitor_printf(mon, "No CPU available\n");
+ return;
+ }
+
+ qmp_memsave(addr, size, filename, true, cpu_index, &err);
hmp_handle_error(mon, &err);
}