]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: make device_set_syspath() more defensive
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Apr 2022 08:18:17 +0000 (10:18 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 11 Apr 2022 14:26:58 +0000 (16:26 +0200)
Simplify generated sysfs paths, since we might get data passed that
includes extra // in the middle.

Also, let's not assume /sys/ prefix without verification.

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

index 89c5b2cdd36b9a882e6789f5b7038517e4496ab8..f9c491c242bc08599850feaaf9d820c0888bc9f3 100644 (file)
@@ -207,10 +207,11 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
                 syspath = strdup(_syspath);
                 if (!syspath)
                         return log_oom_debug();
-        }
 
-        devpath = syspath + STRLEN("/sys");
+                path_simplify(syspath);
+        }
 
+        assert_se(devpath = startswith(syspath, "/sys"));
         if (devpath[0] != '/')
                 return log_debug_errno(SYNTHETIC_ERRNO(ENODEV), "sd-device: \"/sys\" alone is not a valid device path.");