From bc747fbfbf22bdf5bcf3e2b016afdd21bdea6068 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Wed, 13 Feb 2013 17:49:02 -0500 Subject: fix off-by-one error in _alpm_filelist_resolve '/' should not be appended to the resolved root when root is "/". Signed-off-by: Andrew Gregory Signed-off-by: Allan McRae --- lib/libalpm/filelist.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/libalpm/filelist.c') diff --git a/lib/libalpm/filelist.c b/lib/libalpm/filelist.c index f29bb7c4..c4814a49 100644 --- a/lib/libalpm/filelist.c +++ b/lib/libalpm/filelist.c @@ -198,12 +198,16 @@ int _alpm_filelist_resolve(alpm_handle_t *handle, alpm_filelist_t *files) if(realpath(handle->root, path) == NULL){ return -1; } - root_len = strlen(path) + 1; - if(root_len >= PATH_MAX) { + root_len = strlen(path); + if(root_len + 1 >= PATH_MAX) { return -1; } - path[root_len - 1] = '/'; - path[root_len] = '\0'; + /* append '/' if root is not "/" */ + if(path[root_len - 1] != '/') { + path[root_len] = '/'; + root_len++; + path[root_len] = '\0'; + } ret = _alpm_filelist_resolve_link(files, &i, path, root_len, 0); -- cgit v1.2.3-24-g4f1b