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>
This commit is contained in:
parent
140c76d328
commit
03f2e2360a
1 changed files with 8 additions and 1 deletions
|
@ -58,7 +58,7 @@ static int search_path(char **filename, struct stat *bufptr)
|
||||||
|
|
||||||
/* strip the trailing slash if one exists */
|
/* strip the trailing slash if one exists */
|
||||||
while(path[plen - 1] == '/') {
|
while(path[plen - 1] == '/') {
|
||||||
path[--plen] = '\0';
|
path[--plen] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
fullname = malloc(plen + flen + 2);
|
fullname = malloc(plen + flen + 2);
|
||||||
|
@ -133,10 +133,17 @@ static int query_fileowner(alpm_list_t *targets)
|
||||||
const char *bname;
|
const char *bname;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
size_t len;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
filename = strdup(t->data);
|
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(lstat(filename, &buf) == -1) {
|
||||||
/* if it is not a path but a program name, then check in PATH */
|
/* if it is not a path but a program name, then check in PATH */
|
||||||
if(strchr(filename, '/') == NULL) {
|
if(strchr(filename, '/') == NULL) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue