]> git.proxmox.com Git - mirror_qemu.git/blobdiff - hmp.c
monitor: Fix crashes when using HMP commands without CPU
[mirror_qemu.git] / hmp.c
diff --git a/hmp.c b/hmp.c
index 8b0c2b072f7648c914515514297b493ac22577c3..aba728f0de369f710bd2cb2e86c39de8a204e931 100644 (file)
--- 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);
 }