Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2012-07-26 01:04:20 -0400
committerDan McGee <dan@archlinux.org>2012-09-18 08:27:23 -0500
commit03f2e2360ab2950675f9cde32ccc93d1753c6541 (patch)
tree88b250c6c0ace7435abb22decf90c77f612d11de /src
parent140c76d3288b41773411534638305dc8b5928951 (diff)
query_fileowner: remove trailing '/' from targets
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@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/query.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 176f91c2..50b52dd7 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -58,7 +58,7 @@ static int search_path(char **filename, struct stat *bufptr)
/* strip the trailing slash if one exists */
while(path[plen - 1] == '/') {
- path[--plen] = '\0';
+ path[--plen] = '\0';
}
fullname = malloc(plen + flen + 2);
@@ -133,10 +133,17 @@ static int query_fileowner(alpm_list_t *targets)
const char *bname;
struct stat buf;
alpm_list_t *i;
+ size_t len;
int found = 0;
filename = strdup(t->data);
+ /* trailing '/' causes lstat to dereference directory symlinks */
+ len = strlen(filename) - 1;
+ while(len > 0 && filename[len] == '/') {
+ filename[len--] = '\0';
+ }
+
if(lstat(filename, &buf) == -1) {
/* if it is not a path but a program name, then check in PATH */
if(strchr(filename, '/') == NULL) {