sd-device: don't accept /sys as a device path
authorLubomir Rintel <lkundrak@v3.sk>
Mon, 24 Jun 2019 18:38:30 +0000 (20:38 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Jun 2019 01:22:18 +0000 (10:22 +0900)
Because it's not a device path and (slightly) bad things happen if it
gets confused with one:

  $ udevadm info /sys/
  Assertion 'device->devpath[0] == '/'' failed at
      ../src/libsystemd/sd-device/sd-device.c:958,
      function sd_device_get_devpath(). Aborting.
  Aborted (core dumped)

src/libsystemd/sd-device/sd-device.c

index 773be6a..7d5d241 100644 (file)
@@ -201,6 +201,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
 
         devpath = syspath + STRLEN("/sys");
 
+        if (devpath[0] == '\0')
+                /* '/sys' alone is not a valid device path */
+                return -ENODEV;
+
         r = device_add_property_internal(device, "DEVPATH", devpath);
         if (r < 0)
                 return r;