]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
chase-symlinks: honour CHASE_NOFOLLOW flag properly in some cases
authorLennart Poettering <lennart@poettering.net>
Mon, 22 Aug 2022 09:34:40 +0000 (11:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 22 Aug 2022 11:40:13 +0000 (13:40 +0200)
src/basic/chase-symlinks.c

index e93419d63595dfa5c0dd5a2168fd707ec815f775..ab80e766885802349ae47efd5537ec28297e2f20 100644 (file)
@@ -422,7 +422,7 @@ int chase_symlinks_and_open(
 
         if (empty_or_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) {
                 /* Shortcut this call if none of the special features of this call are requested */
-                r = open(path, open_flags);
+                r = open(path, open_flags | (FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? O_NOFOLLOW : 0));
                 if (r < 0)
                         return -errno;
 
@@ -507,7 +507,8 @@ int chase_symlinks_and_stat(
 
         if (empty_or_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) {
                 /* Shortcut this call if none of the special features of this call are requested */
-                if (stat(path, ret_stat) < 0)
+
+                if (fstatat(AT_FDCWD, path, ret_stat, FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0) < 0)
                         return -errno;
 
                 return 1;