]> xenbits.xensource.com Git - libvirt.git/commitdiff
virshFindDisk: Sanitize removable media check
authorPeter Krempa <pkrempa@redhat.com>
Wed, 19 Oct 2022 11:31:00 +0000 (13:31 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 2 Dec 2022 15:49:25 +0000 (16:49 +0100)
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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-domain.c

index 3c6d0984c9e905046a64ef574a74b276c294ac34..5943c3115935fa48b9c13d60e992e1e87dbcac56 100644 (file)
@@ -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;
         }