]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix up remaing work to turn to the current directory before access to the
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 16 Feb 2012 03:15:48 +0000 (12:15 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 16 Feb 2012 03:21:08 +0000 (12:21 +0900)
current entry path at directory traversals.

libarchive/archive_read_disk_posix.c

index cebb305452c1cd14eddabd322dae6b126c3b5d36..0fcd835bf5def49326cee306cfb5e10eaf64a767 100644 (file)
@@ -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 */