From: Yu Watanabe Date: Wed, 28 Sep 2022 09:40:41 +0000 (+0900) Subject: udev-builtin-net_id: do not assume the current interface name is ethX X-Git-Tag: v255-rc1~877^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ded2b1d0933b24d5e0a503e3bd37f8030a11d9a7;p=thirdparty%2Fsystemd.git udev-builtin-net_id: do not assume the current interface name is ethX Otherwise, `udevadm test-builtin` does not work as expected. --- diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index aeb7bceaa57..dbeabf8f0d7 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -501,9 +501,9 @@ static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) { } static int names_vio(sd_device *dev, const char *prefix, bool test) { + const char *syspath, *subsystem, *p, *s; sd_device *parent; - unsigned busid, slotid, ethid; - const char *syspath, *subsystem; + unsigned slotid; int r; assert(dev); @@ -531,12 +531,27 @@ static int names_vio(sd_device *dev, const char *prefix, bool test) { if (r < 0) return log_device_debug_errno(dev, r, "sd_device_get_syspath() failed: %m"); - r = sscanf(syspath, "/sys/devices/vio/%4x%4x/net/eth%u", &busid, &slotid, ðid); - log_device_debug(dev, "Parsing vio slot information from syspath \"%s\": %s", - syspath, r == 3 ? "success" : "failure"); - if (r != 3) + p = path_startswith(syspath, "/sys/devices/vio/"); + if (!p) return -EINVAL; + r = path_find_first_component(&p, /* accept_dot_dot = */ false, &s); + if (r < 0) + return r; + if (r != 8) + return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), + "VIO bus ID and slot ID have invalid length: %s", syspath); + + s = strndupa(s, 8); + if (!in_charset(s, HEXDIGITS)) + return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), + "VIO bus ID and slot ID contain invalid characters: %s", s); + + /* Parse only slot ID (tha last 4 hexdigits). */ + r = safe_atou_full(s + 4, 16, &slotid); + if (r < 0) + return log_device_debug_errno(dev, r, "Failed to parse VIO slot from syspath \"%s\": %m", syspath); + char str[ALTIFNAMSIZ]; if (snprintf_ok(str, sizeof str, "%sv%u", prefix, slotid)) udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);