|
|
5b2ce06 |
From 13ea81b22cde0a429aa1de8b58655296084ce8d7 Mon Sep 17 00:00:00 2001
|
|
|
5b2ce06 |
From: Dmitry Frolov <frolov@swemel.ru>
|
|
|
5b2ce06 |
Date: Tue, 12 Sep 2023 15:56:47 +0300
|
|
|
5b2ce06 |
Subject: [PATCH] interface: fix udev_device_get_sysattr_value return value
|
|
|
5b2ce06 |
check
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
Reviewing the code I found that return value of function
|
|
|
5b2ce06 |
udev_device_get_sysattr_value() is dereferenced without a check.
|
|
|
5b2ce06 |
udev_device_get_sysattr_value() may return NULL by number of reasons.
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
v2: VIR_DEBUG added, replaced STREQ(NULLSTR()) with STREQ_NULLABLE()
|
|
|
5b2ce06 |
v3: More checks added, to skip earlier. More verbose VIR_DEBUG.
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
|
|
|
5b2ce06 |
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
5b2ce06 |
(cherry picked from commit 2ca94317ac642a70921947150ced8acc674ccdc8)
|
|
|
5b2ce06 |
---
|
|
|
5b2ce06 |
src/interface/interface_backend_udev.c | 26 +++++++++++++++++++-------
|
|
|
5b2ce06 |
1 file changed, 19 insertions(+), 7 deletions(-)
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
|
|
|
5b2ce06 |
index 54b43fb999..ef334f175b 100644
|
|
|
5b2ce06 |
--- a/src/interface/interface_backend_udev.c
|
|
|
5b2ce06 |
+++ b/src/interface/interface_backend_udev.c
|
|
|
5b2ce06 |
@@ -23,6 +23,7 @@
|
|
|
5b2ce06 |
#include <dirent.h>
|
|
|
5b2ce06 |
#include <libudev.h>
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
+#include "virlog.h"
|
|
|
5b2ce06 |
#include "virerror.h"
|
|
|
5b2ce06 |
#include "virfile.h"
|
|
|
5b2ce06 |
#include "datatypes.h"
|
|
|
5b2ce06 |
@@ -40,6 +41,8 @@
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
#define VIR_FROM_THIS VIR_FROM_INTERFACE
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
+VIR_LOG_INIT("interface.interface_backend_udev");
|
|
|
5b2ce06 |
+
|
|
|
5b2ce06 |
struct udev_iface_driver {
|
|
|
5b2ce06 |
struct udev *udev;
|
|
|
5b2ce06 |
/* pid file FD, ensures two copies of the driver can't use the same root */
|
|
|
5b2ce06 |
@@ -354,11 +357,20 @@ udevConnectListAllInterfaces(virConnectPtr conn,
|
|
|
5b2ce06 |
const char *macaddr;
|
|
|
5b2ce06 |
g_autoptr(virInterfaceDef) def = NULL;
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
- path = udev_list_entry_get_name(dev_entry);
|
|
|
5b2ce06 |
- dev = udev_device_new_from_syspath(udev, path);
|
|
|
5b2ce06 |
- name = udev_device_get_sysname(dev);
|
|
|
5b2ce06 |
+ if (!(path = udev_list_entry_get_name(dev_entry))) {
|
|
|
5b2ce06 |
+ VIR_DEBUG("Skipping interface, path == NULL");
|
|
|
5b2ce06 |
+ continue;
|
|
|
5b2ce06 |
+ }
|
|
|
5b2ce06 |
+ if (!(dev = udev_device_new_from_syspath(udev, path))) {
|
|
|
5b2ce06 |
+ VIR_DEBUG("Skipping interface '%s', dev == NULL", path);
|
|
|
5b2ce06 |
+ continue;
|
|
|
5b2ce06 |
+ }
|
|
|
5b2ce06 |
+ if (!(name = udev_device_get_sysname(dev))) {
|
|
|
5b2ce06 |
+ VIR_DEBUG("Skipping interface '%s', name == NULL", path);
|
|
|
5b2ce06 |
+ continue;
|
|
|
5b2ce06 |
+ }
|
|
|
5b2ce06 |
macaddr = udev_device_get_sysattr_value(dev, "address");
|
|
|
5b2ce06 |
- status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
|
|
|
5b2ce06 |
+ status = STREQ_NULLABLE(udev_device_get_sysattr_value(dev, "operstate"), "up");
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
def = udevGetMinimalDefForDevice(dev);
|
|
|
5b2ce06 |
if (!virConnectListAllInterfacesCheckACL(conn, def)) {
|
|
|
5b2ce06 |
@@ -962,9 +974,9 @@ udevGetIfaceDef(struct udev *udev, const char *name)
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
/* MTU */
|
|
|
5b2ce06 |
mtu_str = udev_device_get_sysattr_value(dev, "mtu");
|
|
|
5b2ce06 |
- if (virStrToLong_ui(mtu_str, NULL, 10, &mtu) < 0) {
|
|
|
5b2ce06 |
+ if (!mtu_str || virStrToLong_ui(mtu_str, NULL, 10, &mtu) < 0) {
|
|
|
5b2ce06 |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
5b2ce06 |
- _("Could not parse MTU value '%s'"), mtu_str);
|
|
|
5b2ce06 |
+ _("Could not parse MTU value '%s'"), NULLSTR(mtu_str));
|
|
|
5b2ce06 |
goto error;
|
|
|
5b2ce06 |
}
|
|
|
5b2ce06 |
ifacedef->mtu = mtu;
|
|
|
5b2ce06 |
@@ -1087,7 +1099,7 @@ udevInterfaceIsActive(virInterfacePtr ifinfo)
|
|
|
5b2ce06 |
goto cleanup;
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
/* Check if it's active or not */
|
|
|
5b2ce06 |
- status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
|
|
|
5b2ce06 |
+ status = STREQ_NULLABLE(udev_device_get_sysattr_value(dev, "operstate"), "up");
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
udev_device_unref(dev);
|
|
|
5b2ce06 |
|
|
|
5b2ce06 |
--
|
|
|
5b2ce06 |
2.43.0
|
|
|
5b2ce06 |
|