From 6957023208a1c3d5028dbd064d447032689072a2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 22 Aug 2022 11:34:40 +0200 Subject: [PATCH] chase-symlinks: honour CHASE_NOFOLLOW flag properly in some cases --- src/basic/chase-symlinks.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/basic/chase-symlinks.c b/src/basic/chase-symlinks.c index e93419d635..ab80e76688 100644 --- a/src/basic/chase-symlinks.c +++ b/src/basic/chase-symlinks.c @@ -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;