]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path-util: make readlink_value() refuse O_DIRECTORY returned from path_extract_filename()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 19 Apr 2022 16:40:36 +0000 (01:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 19 Apr 2022 16:40:39 +0000 (01:40 +0900)
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.

src/basic/fs-util.c

index 96b588a4b51c46dc2606c18e76d18e66b61a829f..cc25222c32df14403ea2657ea71bc52cde6d0e23 100644 (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) {