[pacman-dev,2/2] remove: Don't follow symlinks in checking if a file can be removed

Message ID 20191127204051.782-2-rymg19@gmail.com
State Changes Requested
Headers show
Series
  • [pacman-dev,1/2] util: Add _alpm_access_flags
Related show

Commit Message

Ryan Gonzalez Nov. 27, 2019, 8:40 p.m. UTC
Otherwise, symlinks to non-removable files will be logged as unable to
be removed.

Signed-off-by: Ryan Gonzalez <rymg19@gmail.com>
---
 lib/libalpm/remove.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Allan McRae Dec. 2, 2019, 5:44 a.m. UTC | #1
On 28/11/19 6:40 am, Ryan Gonzalez wrote:
> Otherwise, symlinks to non-removable files will be logged as unable to
> be removed.
> 
> Signed-off-by: Ryan Gonzalez <rymg19@gmail.com>
> ---
>  lib/libalpm/remove.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
> index 9030bfee..bb980e7d 100644
> --- a/lib/libalpm/remove.c
> +++ b/lib/libalpm/remove.c
> @@ -339,7 +339,7 @@ static int can_remove_file(alpm_handle_t *handle, const alpm_file_t *file)
>  
>  	/* If we fail write permissions due to a read-only filesystem, abort.
>  	 * Assume all other possible failures are covered somewhere else */
> -	if(_alpm_access(handle, NULL, filepath, W_OK) == -1) {
> +	if(_alpm_access_flags(handle, NULL, filepath, W_OK, AT_SYMLINK_NOFOLLOW) == -1) {

AT_SYMLINK_NOFOLLOW is available on Linux and MSYS2 (which are the
largest users of pacman), but not BSD/OSX and we do have some users there.

>  		if(errno != EACCES && errno != ETXTBSY && access(filepath, F_OK) == 0) {
>  			/* only return failure if the file ACTUALLY exists and we can't write to
>  			 * it - ignore "chmod -w" simple permission failures */
>

Patch

diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 9030bfee..bb980e7d 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -339,7 +339,7 @@  static int can_remove_file(alpm_handle_t *handle, const alpm_file_t *file)
 
 	/* If we fail write permissions due to a read-only filesystem, abort.
 	 * Assume all other possible failures are covered somewhere else */
-	if(_alpm_access(handle, NULL, filepath, W_OK) == -1) {
+	if(_alpm_access_flags(handle, NULL, filepath, W_OK, AT_SYMLINK_NOFOLLOW) == -1) {
 		if(errno != EACCES && errno != ETXTBSY && access(filepath, F_OK) == 0) {
 			/* only return failure if the file ACTUALLY exists and we can't write to
 			 * it - ignore "chmod -w" simple permission failures */