1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

path-util: make readlink_value() refuse O_DIRECTORY returned from path_extract_filename()

The function is now only used by sd-device.c and pam_systemd.c, and they
expects the result are not directory. Hence, it is safe to change the
behavior.

Addresses https://github.com/systemd/systemd/pull/23089#discussion_r853006017.
This commit is contained in:
Yu Watanabe 2022-04-20 01:40:36 +09:00
parent c52950c292
commit bb60956b39

View File

@ -155,7 +155,7 @@ int readlink_malloc(const char *p, char **ret) {
}
int readlink_value(const char *p, char **ret) {
_cleanup_free_ char *link = NULL;
_cleanup_free_ char *link = NULL, *name = NULL;
int r;
assert(p);
@ -165,7 +165,14 @@ int readlink_value(const char *p, char **ret) {
if (r < 0)
return r;
return path_extract_filename(link, ret);
r = path_extract_filename(link, &name);
if (r < 0)
return r;
if (r == O_DIRECTORY)
return -EINVAL;
*ret = TAKE_PTR(name);
return 0;
}
int readlink_and_make_absolute(const char *p, char **r) {