diff options
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2017-04-09 19:49:17 -0400 |
---|---|---|
committer | Andrew Gregory <andrew.gregory.8@gmail.com> | 2017-04-16 19:41:35 -0400 |
commit | 16b91f798faf6413f9b043543c5c0c3467b6fdbf (patch) | |
tree | 929d4406c6fe65d234bb5239dd6b027cedd80654 /lib/libalpm | |
parent | f9de3b22ad9e532af14c8d5b0b90a3f0f747e331 (diff) |
unlink_file: strip trailing slashes
If the user replaces a directory with a symlink, libalpm would get
confused because the trailing slash causes system calls to resolve the
symlink. This leads to errors and a misleading message during upgrades.
Even though libalpm does not support this, it should not be giving
misleading errors.
Also adds an overflow check.
Fixes FS#51377
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/remove.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 8ce10f84..ffe92518 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); |