From: Peter Krempa Date: Wed, 19 Oct 2022 11:31:00 +0000 (+0200) Subject: virshFindDisk: Sanitize removable media check X-Git-Tag: v9.0.0-rc1~231 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5911fd808a46d10592e8039a2d679051cb6c614;p=thirdparty%2Flibvirt.git virshFindDisk: Sanitize removable media check The XPath lookup guarantees that the top level element is always 'disk' so there's no need to check that it actually is. We can also remove the two unnecessary temporary variables. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 3c6d0984c9..5943c31159 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12658,22 +12658,13 @@ virshFindDisk(const char *doc, /* search disk using @path */ for (i = 0; i < nnodes; i++) { - bool is_supported = true; - if (type == VIRSH_FIND_DISK_CHANGEABLE) { - xmlNodePtr n = nodes[i]; - is_supported = false; + g_autofree char *device = virXMLPropString(nodes[i], "device"); /* Check if the disk is CDROM or floppy disk */ - if (virXMLNodeNameEqual(n, "disk")) { - g_autofree char *device_value = virXMLPropString(n, "device"); - - if (STREQ(device_value, "cdrom") || - STREQ(device_value, "floppy")) - is_supported = true; - } - - if (!is_supported) + if (device && + STRNEQ(device, "cdrom") && + STRNEQ(device, "floppy")) continue; }