From: Yu Watanabe Date: Tue, 19 Apr 2022 16:40:36 +0000 (+0900) Subject: path-util: make readlink_value() refuse O_DIRECTORY returned from path_extract_filename() X-Git-Tag: v251-rc2~95^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb60956b393c3534fb4960772c7fd023aa0f81d5;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 96b588a4b51..cc25222c32d 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -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) {