Bugfix: Handle error if VM Generation ID device not present
authorBen Warren <ben@skyportsystems.com>
Thu, 2 Mar 2017 21:36:50 +0000 (13:36 -0800)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 15 Mar 2017 17:37:19 +0000 (19:37 +0200)
This was crashing due to NULL-pointer dereference

QMP Test case:
==============

(QEMU) query-vm-generation-id
{"error": {"class": "GenericError", "desc": "VM Generation ID device not
found"}}

HMP Test case:
==============
virsh # qemu-monitor-command --hmp 3 info vm-generation-id
VM Generation ID device not found

Signed-off-by: Ben Warren <ben@skyportsystems.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
hmp.c
hw/acpi/vmgenid.c

diff --git a/hmp.c b/hmp.c
index 261843f7a25e84e6130187367966b879766135af..edb8970461fb63b7b55e0a3a5338e148d119d4c1 100644 (file)
--- a/hmp.c
+++ b/hmp.c
@@ -2608,9 +2608,11 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
 
 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
 {
-    GuidInfo *info = qmp_query_vm_generation_id(NULL);
+    Error *err = NULL;
+    GuidInfo *info = qmp_query_vm_generation_id(&err);
     if (info) {
         monitor_printf(mon, "%s\n", info->guid);
     }
+    hmp_handle_error(mon, &err);
     qapi_free_GuidInfo(info);
 }
index 744f2847da48ff9affefeb9ef855a8c528aefba2..7a3ad17d66ef58849deed24a4f18fbde06e058b7 100644 (file)
@@ -248,6 +248,7 @@ GuidInfo *qmp_query_vm_generation_id(Error **errp)
     Object *obj = find_vmgenid_dev();
 
     if (!obj) {
+        error_setg(errp, "VM Generation ID device not found");
         return NULL;
     }
     vms = VMGENID(obj);