[libvirt] [PATCH] qemu_monitor_json: Properly check GetArray return value

Jiri Denemark posted 1 patch 7 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/4a5f21310ea9e2b6bbf8e6bb040b360ec45c17d9.1487072287.git.jdenemar@redhat.com
src/qemu/qemu_monitor_json.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
[libvirt] [PATCH] qemu_monitor_json: Properly check GetArray return value
Posted by Jiri Denemark 7 years, 1 month ago
Commit 2a8d40f4ec refactored qemuMonitorJSONGetCPUx86Data and replaced
virJSONValueObjectGet(reply, "return") with virJSONValueObjectGetArray.
While the former is guaranteed to always return non-NULL pointer the
latter may return NULL if the returned JSON object is not an array.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_monitor_json.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index e30b72cd4..1d281af48 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6554,7 +6554,7 @@ qemuMonitorJSONParseCPUx86Features(virJSONValuePtr data,
     ssize_t n;
     int ret = -1;
 
-    if ((n = virJSONValueArraySize(data)) < 0) {
+    if (!data || (n = virJSONValueArraySize(data)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("invalid array of CPUID features"));
         return -1;
@@ -6644,9 +6644,8 @@ qemuMonitorJSONCheckCPUx86(qemuMonitorPtr mon)
     if (qemuMonitorJSONCheckError(cmd, reply))
         goto cleanup;
 
-    data = virJSONValueObjectGetArray(reply, "return");
-
-    if ((n = virJSONValueArraySize(data)) < 0) {
+    if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
+        (n = virJSONValueArraySize(data)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("qom-list reply data was not an array"));
         goto cleanup;
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu_monitor_json: Properly check GetArray return value
Posted by Michal Privoznik 7 years, 1 month ago
On 02/14/2017 12:38 PM, Jiri Denemark wrote:
> Commit 2a8d40f4ec refactored qemuMonitorJSONGetCPUx86Data and replaced
> virJSONValueObjectGet(reply, "return") with virJSONValueObjectGetArray.
> While the former is guaranteed to always return non-NULL pointer the
> latter may return NULL if the returned JSON object is not an array.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/qemu/qemu_monitor_json.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list