]> xenbits.xensource.com Git - libvirt.git/commitdiff
udevListInterfacesByStatus: Don't try to return NULL names
authorPeter Krempa <pkrempa@redhat.com>
Mon, 6 May 2024 15:44:42 +0000 (17:44 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 7 May 2024 12:55:57 +0000 (14:55 +0200)
In case when the interface is being detached/reattached it may happen
that udev will return NULL from 'udev_device_get_sysname()'.

As the RPC code requires nonnull strings in the return array it fails to
serialize such reply:

 libvirt: XML-RPC error : Unable to encode message payload

Fix this by simply ignoring such interfaces as there's nothing we can
report in such case.

A similar fix was done to 'udevConnectListAllInterfaces' in commit
2ca94317ac6.

Resolves: https://issues.redhat.com/browse/RHEL-34615
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/interface/interface_backend_udev.c

index 826f48604940a75ac6c070e684a99c4cd8d655e3..8bb19d77642beda958ad660120d9259ed655d98d 100644 (file)
@@ -185,6 +185,7 @@ udevListInterfacesByStatus(virConnectPtr conn,
     udev_list_entry_foreach(dev_entry, devices) {
         struct udev_device *dev;
         const char *path;
+        const char *name;
         g_autoptr(virInterfaceDef) def = NULL;
 
         /* Ensure we won't exceed the size of our array */
@@ -194,10 +195,17 @@ udevListInterfacesByStatus(virConnectPtr conn,
         path = udev_list_entry_get_name(dev_entry);
         dev = udev_device_new_from_syspath(udev, path);
 
+        if (!(name = udev_device_get_sysname(dev))) {
+            /* Name can be NULL in case when the interface is being unbound
+             * from the driver. The list API requires names to be present */
+            VIR_DEBUG("Skipping interface '%s', name == NULL", path);
+            continue;
+        }
+
         def = udevGetMinimalDefForDevice(dev);
         if (filter(conn, def)) {
             if (names)
-                names[count] = g_strdup(udev_device_get_sysname(dev));
+                names[count] = g_strdup(name);
             count++;
         }
         udev_device_unref(dev);