sd-device: make device_set_syspath() more defensive

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.
This commit is contained in:
Lennart Poettering
2022-04-05 10:18:17 +02:00
parent 09c24f76dc
commit 4d960d0bdb

View 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();
path_simplify(syspath);
}
devpath = syspath + STRLEN("/sys");
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.");