From b4f11d5496a9f638278c8927f0c6032a332c75b5 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Fri, 1 Oct 2021 21:13:18 +0100 Subject: [PATCH] alpm: test access of symlinks not where they point On platforms that have AT_SYMLINK_NOFOLLOW Fixes FS#69720 --- lib/libalpm/util.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index dffa3b51..3ded403d 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1352,6 +1353,11 @@ int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int a size_t len = 0; int ret = 0; + int flag = 0; +#ifdef AT_SYMLINK_NOFOLLOW + flag |= AT_SYMLINK_NOFOLLOW; +#endif + if(dir) { char *check_path; @@ -1359,11 +1365,11 @@ int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int a CALLOC(check_path, len, sizeof(char), RET_ERR(handle, ALPM_ERR_MEMORY, -1)); snprintf(check_path, len, "%s%s", dir, file); - ret = access(check_path, amode); + ret = faccessat(AT_FDCWD, check_path, amode, flag); free(check_path); } else { dir = ""; - ret = access(file, amode); + ret = faccessat(AT_FDCWD, file, amode, flag); } if(ret != 0) {