[pacman-dev] [PATCH 3/3] query_fileowner: remove trailing '/' from targets

Allan McRae allan at archlinux.org
Sun Jul 22 23:18:24 EDT 2012


On 23/07/12 03:30, Andrew Gregory wrote:
> Trailing '/' in paths causes lstat to dereference symlinks to directories which
> causes it to break even though the symlink is a valid target.
> 
> Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
> ---
>  src/pacman/query.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/pacman/query.c b/src/pacman/query.c
> index 84c9d3b..dca45e7 100644
> --- a/src/pacman/query.c
> +++ b/src/pacman/query.c
> @@ -136,6 +136,12 @@ static int query_fileowner(alpm_list_t *targets)
>  
>  		filename = strdup(t->data);
>  
> +		/* trailing '/' causes lstat to resolve directory symlinks */
> +		size_t len = strlen(filename) - 1;
> +		while(len > 0 && filename[len] == '/'){
> +			filename[len] = '\0';
> +		}

while?  Are you wanting to remove multiple trailing '/' at the and of
the path and forgot to add a decrement here?

> +
>  		if(lstat(filename, &buf) == -1) {
>  			/*  if it is not a path but a program name, then check in PATH */
>  			if(strchr(filename, '/') == NULL) {
> 



More information about the pacman-dev mailing list