]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: fix segfault when error occurs in device_new_from_{nulstr,strv}()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 22 Dec 2018 18:06:47 +0000 (03:06 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 30 Dec 2018 13:47:20 +0000 (22:47 +0900)
As devpath may not be set yet.

When debug logging is enabled, log_device_*() calls
sd_device_get_sysname(). So, we should not assume that devpath is always
set.

Fixes #11258.

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

index db58615df53df64109360cdd469ac5d17ad5fcbf..9b1ef4448030c417654f978f2b8a46e01260f411 100644 (file)
@@ -1002,6 +1002,9 @@ static int device_set_sysname(sd_device *device) {
         const char *pos;
         size_t len = 0;
 
+        if (!device->devpath)
+                return -EINVAL;
+
         pos = strrchr(device->devpath, '/');
         if (!pos)
                 return -EINVAL;