index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2017-04-09 19:49:17 -0400 |
---|---|---|
committer | Andrew Gregory <andrew.gregory.8@gmail.com> | 2017-05-08 23:27:44 -0400 |
commit | 0fd8455c66ae574e479f9d9a645f2e8366bac993 (patch) | |
tree | fbebbef6602275cbfb1611c424457276bea56474 /lib/libalpm/remove.c | |
parent | 908769b54002e104b90ab2b3e5ca8066affd4394 (diff) |
-rw-r--r-- | lib/libalpm/remove.c | 13 |
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 173dbc69..ee8f288e 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -440,8 +440,19 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg, { struct stat buf; char file[PATH_MAX]; + int file_len; - snprintf(file, PATH_MAX, "%s%s", handle->root, fileobj->name); + file_len = snprintf(file, PATH_MAX, "%s%s", handle->root, fileobj->name); + if(file_len <= 0 || file_len >= PATH_MAX) { + /* 0 is a valid value from snprintf, but should be impossible here */ + _alpm_log(handle, ALPM_LOG_DEBUG, "path too long to unlink %s%s\n", + handle->root, fileobj->name); + return -1; + } else if(file[file_len-1] == '/') { + /* trailing slashes cause errors and confusing messages if the user has + * replaced a directory with a symlink */ + file[--file_len] = '\0'; + } if(llstat(file, &buf)) { _alpm_log(handle, ALPM_LOG_DEBUG, "file %s does not exist\n", file); |