diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-04-19 18:43:11 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-04-19 18:43:27 +0200 |
commit | e4e1353c251e253b7cdf48db41b27572b6ed9172 (patch) | |
tree | 513f2c440a25ead8a58216b68fd74a7f9ac274d7 /src | |
parent | path-util: make readlink_value() refuse O_DIRECTORY returned from path_extrac... (diff) | |
download | systemd-e4e1353c251e253b7cdf48db41b27572b6ed9172.tar.xz systemd-e4e1353c251e253b7cdf48db41b27572b6ed9172.zip |
sd-device: refuse O_DIRECTORY returned from path_extract_filename()
In both cases, it is expected that the symlink targets do not end with '/'.
Addresses https://github.com/systemd/systemd/pull/23089#discussion_r853007218.
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 0c5b2a67e3..bf9c753db5 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1181,6 +1181,8 @@ static int device_set_sysname_and_sysnum(sd_device *device) { r = path_extract_filename(device->devpath, &sysname); if (r < 0) return r; + if (r == O_DIRECTORY) + return -EINVAL; /* some devices have '!' in their name, change that to '/' */ for (p = strchrnul(sysname, '!'); *p != '\0'; p = strchrnul(p, '!')) @@ -1457,6 +1459,8 @@ int device_get_device_id(sd_device *device, const char **ret) { r = path_extract_filename(device->devpath, &sysname); if (r < 0) return r; + if (r == O_DIRECTORY) + return -EINVAL; if (streq(subsystem, "drivers")) { /* the 'drivers' pseudo-subsystem is special, and needs the real |