]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 203. Fix build failure without PATH_MAX.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 26 Dec 2011 02:38:42 +0000 (21:38 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 26 Dec 2011 02:38:42 +0000 (21:38 -0500)
Merge r4004 and r4005 from trunk.

SVN-Revision: 4006

libarchive/archive_write_set_format_xar.c
libarchive/test/test_sparse_basic.c

index 4447f5a8fa86afbe54092a65c092e3a044f8506b..bb9b551848752b92d3ee24fdc47dd8a032a6992c 100644 (file)
@@ -684,21 +684,24 @@ xar_write_data(struct archive_write *a, const void *buff, size_t s)
 
                archive_string_empty(&(xar->cur_file->script));
                if (rsize > 2 && b[0] == '#' && b[1] == '!') {
-                       char path[PATH_MAX];
                        size_t i, end, off;
 
-                       end = sizeof(path);
-                       if (end > rsize)
-                               end = rsize;
                        off = 2;
                        if (b[off] == ' ')
                                off++;
+#ifdef PATH_MAX
+                       if ((rsize - off) > PATH_MAX)
+                               end = off + PATH_MAX;
+                       else
+#endif
+                               end = rsize;
+                       /* Find the end of a script path. */
                        for (i = off; i < end && b[i] != '\0' &&
                            b[i] != '\n' && b[i] != '\r' &&
                            b[i] != ' ' && b[i] != '\t'; i++)
-                               path[i - off] = b[i];
-                       path[i - off] = '\0';
-                       archive_strcpy(&(xar->cur_file->script), path);
+                               ;
+                       archive_strncpy(&(xar->cur_file->script), b + off,
+                           i - off);
                }
        }
 #endif
index e8c2f3385d1896b26b6a8f7d61e6260610bd13db..0656f2ff732322750b357cdfb89fb87d9c22eb94 100644 (file)
@@ -360,7 +360,7 @@ test_sparse_whole_file_data()
 
 DEFINE_TEST(test_sparse_basic)
 {
-       char cwd[PATH_MAX+1];
+       char *cwd;
        struct archive *a;
        /*
         * The alignment of the hole of sparse files deeply depends
@@ -420,9 +420,15 @@ DEFINE_TEST(test_sparse_basic)
 
        /* Check if the filesystem where CWD on can
         * report the number of the holes of a sparse file. */
-       if (!assert(getcwd(cwd, sizeof(cwd)-1) != NULL))
+#ifdef PATH_MAX
+       cwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
+#else
+       cwd = getcwd(NULL, 0);
+#endif
+       if (!assert(cwd != NULL))
                return;
        if (!is_sparse_supported(cwd)) {
+               free(cwd);
                skipping("This filesystem or platform do not support "
                    "the reporting of the holes of a sparse file through "
                    "API such as lseek(HOLE)");
@@ -450,4 +456,5 @@ DEFINE_TEST(test_sparse_basic)
        verify_sparse_file2(a, "file0", sparse_file0, 5, 1);
 
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+       free(cwd);
 }