From d915721bf234e15b7f72d6bdde815035b012fccb Mon Sep 17 00:00:00 2001
From: luowei <luowei@kylinos.cn>
Date: Wed, 22 Oct 2025 17:00:10 +0800
Subject: [PATCH] virshFindDisk: fix NULL-dereference of xmlCopyNode() result
cheery-pick from 1eaaec533abbad52a40c282f1f1d009248c08e3d
xmlCopyNode() may return NULL. Add a check and log an error
in this case.
Found by Linux Verification Center (linuxtesting.org) with Svace.
Fixes: 22766a1a ("virshFindDisk: Sanitize use of 'tmp' variable")
Signed-off-by: default avatarAnastasia Belova <abelova@astralinux.ru>
Reviewed-by: default avatarPeter Krempa <pkrempa@redhat.com>
tools/virsh-domain.c | 4 ++++
1 file changed, 4 insertions(+)
@@ -12772,6 +12772,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;
--
2.52.0.windows.1