]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
domain_conf: fix NULL dereference on error in virDomainObjCopyPersistentDef
authorPavel Hrdina <phrdina@redhat.com>
Wed, 11 Mar 2020 12:25:59 +0000 (13:25 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 16 Nov 2020 16:13:42 +0000 (17:13 +0100)
The issue was introduced together with the function itself by commit
<da1eba6bc8f58bfce34136710d1979a3a44adb17>.  Calling
`virDomainObjGetPersistentDef` may return NULL which is later passed
to `virDomainDefFormat` where the `def` attribute is marked as NONNULL
and later in `virDomainDefFormatInternalSetRootName` it is actually
defererenced without any other check.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/conf/domain_conf.c

index 5c30227212d2b19b42677de1d5234befd9f9178b..bf97e0505d17faa7dbc74e200eb8ac01f4b9f102 100644 (file)
@@ -30933,6 +30933,12 @@ virDomainObjCopyPersistentDef(virDomainObjPtr dom,
     virDomainDefPtr cur;
 
     cur = virDomainObjGetPersistentDef(xmlopt, dom, parseOpaque);
+    if (!cur) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("failed to get persistent definition object"));
+        return NULL;
+    }
+
     return virDomainDefCopy(cur, xmlopt, parseOpaque, false);
 }