Blame SOURCES/libvirt-qemu-monitor-Make-qemuMonitorAddObject-more-robust-against-programming-errors.patch

edecca
From 08a2ab563571018ea8c4eb0ac34acc9f4913c714 Mon Sep 17 00:00:00 2001
edecca
Message-Id: <08a2ab563571018ea8c4eb0ac34acc9f4913c714@dist-git>
edecca
From: Peter Krempa <pkrempa@redhat.com>
edecca
Date: Tue, 10 Jul 2018 17:41:11 +0200
edecca
Subject: [PATCH] qemu: monitor: Make qemuMonitorAddObject more robust against
edecca
 programming errors
edecca
MIME-Version: 1.0
edecca
Content-Type: text/plain; charset=UTF-8
edecca
Content-Transfer-Encoding: 8bit
edecca
edecca
Document and check that @props contains a pointer to a json object and
edecca
check that both necessary fields are present. Also mark @props as
edecca
NONNULL.
edecca
edecca
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
edecca
Reviewed-by: Ján Tomko <jtomko@redhat.com>
edecca
(cherry picked from commit fac0dacd54c02b842c995d0999d9450d09d1e7cd)
edecca
edecca
https: //bugzilla.redhat.com/show_bug.cgi?id=1598015
edecca
Reviewed-by: Ján Tomko <jtomko@redhat.com>
edecca
---
edecca
 src/qemu/qemu_monitor.c | 23 +++++++++++++++++------
edecca
 src/qemu/qemu_monitor.h |  3 ++-
edecca
 2 files changed, 19 insertions(+), 7 deletions(-)
edecca
edecca
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
edecca
index 6ed475ede0..ae5b23b9fc 100644
edecca
--- a/src/qemu/qemu_monitor.c
edecca
+++ b/src/qemu/qemu_monitor.c
edecca
@@ -3073,8 +3073,9 @@ qemuMonitorCreateObjectProps(virJSONValuePtr *propsret,
edecca
 /**
edecca
  * qemuMonitorAddObject:
edecca
  * @mon: Pointer to monitor object
edecca
- * @props: Optional arguments for the given type. The object is consumed and
edecca
- *         the pointer is cleared.
edecca
+ * @props: Pointer to a JSON object holding configuration of the object to add.
edecca
+ *         The object must be non-null and contain at least the "qom-type" and
edecca
+ *         "id" field. The object is consumed and the pointer is cleared.
edecca
  * @alias: If not NULL, returns the alias of the added object if it was added
edecca
  *         successfully to qemu. Caller should free the returned pointer.
edecca
  *
edecca
@@ -3085,18 +3086,28 @@ qemuMonitorAddObject(qemuMonitorPtr mon,
edecca
                      virJSONValuePtr *props,
edecca
                      char **alias)
edecca
 {
edecca
-    const char *type = virJSONValueObjectGetString(*props, "qom-type");
edecca
-    const char *id = virJSONValueObjectGetString(*props, "id");
edecca
+    const char *type = NULL;
edecca
+    const char *id = NULL;
edecca
     char *tmp = NULL;
edecca
     int ret = -1;
edecca
 
edecca
+    if (!*props) {
edecca
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
edecca
+                       _("object props can't be NULL"));
edecca
+        goto cleanup;
edecca
+    }
edecca
+
edecca
+    type = virJSONValueObjectGetString(*props, "qom-type");
edecca
+    id = virJSONValueObjectGetString(*props, "id");
edecca
+
edecca
     VIR_DEBUG("type=%s id=%s", NULLSTR(type), NULLSTR(id));
edecca
 
edecca
     QEMU_CHECK_MONITOR_GOTO(mon, cleanup);
edecca
 
edecca
-    if (!id) {
edecca
+    if (!id || !type) {
edecca
         virReportError(VIR_ERR_INTERNAL_ERROR,
edecca
-                       _("missing alias for qemu object '%s'"), NULLSTR(type));
edecca
+                       _("missing alias or qom-type for qemu object '%s'"),
edecca
+                       NULLSTR(type));
edecca
         goto cleanup;
edecca
     }
edecca
 
edecca
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
edecca
index b3d62324b4..e8adda8aa0 100644
edecca
--- a/src/qemu/qemu_monitor.h
edecca
+++ b/src/qemu/qemu_monitor.h
edecca
@@ -812,7 +812,8 @@ int qemuMonitorCreateObjectProps(virJSONValuePtr *propsret,
edecca
 
edecca
 int qemuMonitorAddObject(qemuMonitorPtr mon,
edecca
                          virJSONValuePtr *props,
edecca
-                         char **alias);
edecca
+                         char **alias)
edecca
+    ATTRIBUTE_NONNULL(1);
edecca
 
edecca
 int qemuMonitorDelObject(qemuMonitorPtr mon,
edecca
                          const char *objalias);
edecca
-- 
edecca
2.18.0
edecca