summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-device
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-04-05 10:18:17 +0200
committerLennart Poettering <lennart@poettering.net>2022-04-11 16:26:58 +0200
commit4d960d0bdb373b6bb71f77f8a3032795d60284c3 (patch)
tree401fb1bf2d425b8c368f91222922cc17093d7806 /src/libsystemd/sd-device
parent09c24f76dce5f606056d916207676f2a93157deb (diff)
downloadsystemd-4d960d0bdb373b6bb71f77f8a3032795d60284c3.tar.gz
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.
Diffstat (limited to 'src/libsystemd/sd-device')
-rw-r--r--src/libsystemd/sd-device/sd-device.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index 89c5b2cdd3..f9c491c242 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -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.");