]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virshFindDisk: fix NULL-dereference of xmlCopyNode() result
authorAnastasia Belova <abelova@astralinux.ru>
Wed, 16 Jul 2025 13:42:14 +0000 (16:42 +0300)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 17 Jul 2025 10:54:17 +0000 (12:54 +0200)
xmlCopyNode() may return NULL. Add a check and log an error
in this case.

Found by Linux Verification Center (linuxtesting.org) with Svace.

Fixes: 22766a1a53 ("virshFindDisk: Sanitize use of 'tmp' variable")
Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
tools/virsh-domain.c

index 7253596f4ac8ac95f398554055995b46dddefdef..6e18d195e6d1c2e073f074c668168c33a7aee359 100644 (file)
@@ -12875,6 +12875,10 @@ virshFindDisk(const char *doc,
             STREQ_NULLABLE(sourceDir, path) ||
             STREQ_NULLABLE(sourceName, path)) {
             xmlNodePtr ret = xmlCopyNode(nodes[i], 1);
+            if (!ret) {
+                vshError(NULL, "%s", _("Failed to copy XML node"));
+                return NULL;
+            }
             /* drop backing store since they are not needed here */
             virshDiskDropBackingStore(ret);
             return ret;