]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: firmware: check virJSONValueObjectGet return value
authorJán Tomko <jtomko@redhat.com>
Tue, 22 Sep 2020 21:22:06 +0000 (23:22 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 23 Sep 2020 11:26:34 +0000 (13:26 +0200)
If the mapping is not present, we should not try to
access its elements.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 8b5b80f4c5f7342eedce0747469223387ab709ef
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_firmware.c

index ffe2df20aa6f85d8e2a5f887a8f5972498266f9e..480ce0b00d53db817384df78595c7ec81c276c4d 100644 (file)
@@ -434,10 +434,17 @@ qemuFirmwareMappingParse(const char *path,
                          virJSONValuePtr doc,
                          qemuFirmwarePtr fw)
 {
-    virJSONValuePtr mapping = virJSONValueObjectGet(doc, "mapping");
+    virJSONValuePtr mapping;
     const char *deviceStr;
     int tmp;
 
+    if (!(mapping = virJSONValueObjectGet(doc, "mapping"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("missing mapping in '%s'"),
+                       path);
+        return -1;
+    }
+
     if (!(deviceStr = virJSONValueObjectGetString(mapping, "device"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("missing device type in '%s'"),