1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

udevListInterfacesByStatus: Don't try to return NULL names

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
2ca94317ac.

Resolves: https://issues.redhat.com/browse/RHEL-34615
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2024-05-06 17:44:42 +02:00
parent bc596f2751
commit df9ffb0256

View 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);