From: Michihiro NAKAJIMA Date: Thu, 16 Feb 2012 03:15:48 +0000 (+0900) Subject: Fix up remaing work to turn to the current directory before access to the X-Git-Tag: v3.0.4~2^2~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf6fc3be7dde40e7c752762654938d80e5222b48;p=thirdparty%2Flibarchive.git Fix up remaing work to turn to the current directory before access to the current entry path at directory traversals. --- diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c index cebb30545..0fcd835bf 100644 --- a/libarchive/archive_read_disk_posix.c +++ b/libarchive/archive_read_disk_posix.c @@ -1537,9 +1537,13 @@ setup_current_filesystem(struct archive_read_disk *a) t->current_filesystem->name_max = sfs.f_namemax; #else /* Mac OS X does not have f_namemax in struct statfs. */ - if (tree_current_is_symblic_link_target(t)) + if (tree_current_is_symblic_link_target(t)) { + if (tree_enter_working_dir(t) != 0) { + archive_set_error(&a->archive, errno, "fchdir failed"); + return (ARCHIVE_FAILED); + } nm = pathconf(tree_current_access_path(t), _PC_NAME_MAX); - else + } else nm = fpathconf(tree_current_dir_fd(t), _PC_NAME_MAX); if (nm == -1) t->current_filesystem->name_max = NAME_MAX; @@ -1563,6 +1567,10 @@ setup_current_filesystem(struct archive_read_disk *a) int r, xr = 0; t->current_filesystem->synthetic = -1; + if (tree_enter_working_dir(t) != 0) { + archive_set_error(&a->archive, errno, "fchdir failed"); + return (ARCHIVE_FAILED); + } if (tree_current_is_symblic_link_target(t)) { r = statvfs(tree_current_access_path(t), &sfs); if (r == 0) @@ -1837,9 +1845,13 @@ setup_current_filesystem(struct archive_read_disk *a) #if defined(HAVE_READDIR_R) /* Set maximum filename length. */ # if defined(_PC_NAME_MAX) - if (tree_current_is_symblic_link_target(t)) + if (tree_current_is_symblic_link_target(t)) { + if (tree_enter_working_dir(t) != 0) { + archive_set_error(&a->archive, errno, "fchdir failed"); + return (ARCHIVE_FAILED); + } nm = pathconf(tree_current_access_path(t), _PC_NAME_MAX); - else + } else nm = fpathconf(tree_current_dir_fd(t), _PC_NAME_MAX); if (nm == -1) # endif /* _PC_NAME_MAX */