[pacman-dev] [PATCH] diskspace: ensure we match only full path components
Dan McGee
dan at archlinux.org
Mon Feb 20 00:05:36 EST 2012
If one had a mountpoint at '/e' (don't ask), a file being installed to
'/etc' would map to it incorrectly. Ensure we do more than just prefix
matching on paths by doing some more sanity checks once the simple
strncmp() call succeeds.
Signed-off-by: Dan McGee <dan at archlinux.org>
---
lib/libalpm/diskspace.c | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index d0f52a6..45908b2 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -179,8 +179,20 @@ static alpm_mountpoint_t *match_mount_point(const alpm_list_t *mount_points,
for(mp = mount_points; mp != NULL; mp = mp->next) {
alpm_mountpoint_t *data = mp->data;
+ /* first, check if the prefix matches */
if(strncmp(data->mount_dir, real_path, data->mount_dir_len) == 0) {
- return data;
+ /* now, the hard work- a file like '/etc/myconfig' shouldn't map to a
+ * mountpoint '/e', but only '/etc'. If the mountpoint ends in a trailing
+ * slash, we know we didn't have a mismatch, otherwise we have to do some
+ * more sanity checks. */
+ if(data->mount_dir[data->mount_dir_len - 1] == '/') {
+ return data;
+ } else if(strlen(real_path) >= data->mount_dir_len) {
+ const char next = real_path[data->mount_dir_len];
+ if(next == '/' || next == '\0') {
+ return data;
+ }
+ }
}
}
--
1.7.9.1
More information about the pacman-dev
mailing list