summaryrefslogtreecommitdiff
path: root/archivers/libarchive/files/cpio
diff options
context:
space:
mode:
Diffstat (limited to 'archivers/libarchive/files/cpio')
-rw-r--r--archivers/libarchive/files/cpio/cpio.c19
-rw-r--r--archivers/libarchive/files/cpio/test/test_basic.c4
-rw-r--r--archivers/libarchive/files/cpio/test/test_format_newc.c7
-rw-r--r--archivers/libarchive/files/cpio/test/test_gcpio_compat.c2
-rw-r--r--archivers/libarchive/files/cpio/test/test_option_L_upper.c14
-rw-r--r--archivers/libarchive/files/cpio/test/test_option_a.c5
-rw-r--r--archivers/libarchive/files/cpio/test/test_option_c.c2
-rw-r--r--archivers/libarchive/files/cpio/test/test_option_t.c8
8 files changed, 42 insertions, 19 deletions
diff --git a/archivers/libarchive/files/cpio/cpio.c b/archivers/libarchive/files/cpio/cpio.c
index 4b8ce79296f..4fd394dea5f 100644
--- a/archivers/libarchive/files/cpio/cpio.c
+++ b/archivers/libarchive/files/cpio/cpio.c
@@ -134,8 +134,9 @@ main(int argc, char *argv[])
struct cpio _cpio; /* Allocated on stack. */
struct cpio *cpio;
const char *errmsg;
+ char *tptr;
int uid, gid;
- int opt;
+ int opt, t;
cpio = &_cpio;
memset(cpio, 0, sizeof(*cpio));
@@ -204,9 +205,15 @@ main(int argc, char *argv[])
cpio->add_filter = opt;
break;
case 'C': /* NetBSD/OpenBSD */
- cpio->bytes_per_block = atoi(cpio->argument);
- if (cpio->bytes_per_block <= 0)
- lafe_errc(1, 0, "Invalid blocksize %s", cpio->argument);
+ errno = 0;
+ tptr = NULL;
+ t = (int)strtol(cpio->argument, &tptr, 10);
+ if (errno || t <= 0 || *(cpio->argument) == '\0' ||
+ tptr == NULL || *tptr != '\0') {
+ lafe_errc(1, 0, "Invalid blocksize: %s",
+ cpio->argument);
+ }
+ cpio->bytes_per_block = t;
break;
case 'c': /* POSIX 1997 */
cpio->format = "odc";
@@ -748,8 +755,10 @@ file_to_archive(struct cpio *cpio, const char *srcpath)
}
if (cpio->option_rename)
destpath = cpio_rename(destpath);
- if (destpath == NULL)
+ if (destpath == NULL) {
+ archive_entry_free(entry);
return (0);
+ }
archive_entry_copy_pathname(entry, destpath);
/*
diff --git a/archivers/libarchive/files/cpio/test/test_basic.c b/archivers/libarchive/files/cpio/test/test_basic.c
index 6e45d185698..a8fedf89e96 100644
--- a/archivers/libarchive/files/cpio/test/test_basic.c
+++ b/archivers/libarchive/files/cpio/test/test_basic.c
@@ -46,7 +46,7 @@ verify_files(const char *msg)
/* Symlink */
if (canSymlink())
- assertIsSymlink("symlink", "file");
+ assertIsSymlink("symlink", "file", 0);
/* Another file with 1 link and different permissions. */
failure(msg);
@@ -173,7 +173,7 @@ DEFINE_TEST(test_basic)
/* Symlink to above file. */
if (canSymlink()) {
- assertMakeSymlink("symlink", "file");
+ assertMakeSymlink("symlink", "file", 0);
fprintf(filelist, "symlink\n");
if (is_LargeInode("symlink")) {
strncat(result,
diff --git a/archivers/libarchive/files/cpio/test/test_format_newc.c b/archivers/libarchive/files/cpio/test/test_format_newc.c
index 258640443fe..6c981f6ac13 100644
--- a/archivers/libarchive/files/cpio/test/test_format_newc.c
+++ b/archivers/libarchive/files/cpio/test/test_format_newc.c
@@ -114,7 +114,7 @@ DEFINE_TEST(test_format_newc)
/* "symlink" */
if (canSymlink()) {
- assertMakeSymlink("symlink", "file1");
+ assertMakeSymlink("symlink", "file1", 0);
fprintf(list, "symlink\n");
}
@@ -233,7 +233,12 @@ DEFINE_TEST(test_format_newc)
assert(is_hex(e, 110));
assertEqualMem(e + 0, "070701", 6); /* Magic */
assert(is_hex(e + 6, 8)); /* ino */
+#if defined(_WIN32) && !defined(CYGWIN)
+ /* Mode: Group members bits and others bits do not work. */
+ assertEqualInt(0xa180, from_hex(e + 14, 8) & 0xffc0);
+#else
assertEqualInt(0xa1ff, from_hex(e + 14, 8)); /* Mode */
+#endif
assertEqualInt(from_hex(e + 22, 8), uid); /* uid */
assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */
assertEqualMem(e + 38, "00000001", 8); /* nlink */
diff --git a/archivers/libarchive/files/cpio/test/test_gcpio_compat.c b/archivers/libarchive/files/cpio/test/test_gcpio_compat.c
index 461e427c2e8..9bb988990e4 100644
--- a/archivers/libarchive/files/cpio/test/test_gcpio_compat.c
+++ b/archivers/libarchive/files/cpio/test/test_gcpio_compat.c
@@ -71,7 +71,7 @@ unpack_test(const char *from, const char *options, const char *se)
/* Symlink */
if (canSymlink())
- assertIsSymlink("symlink", "file");
+ assertIsSymlink("symlink", "file", 0);
/* dir */
assertIsDir("dir", 0775);
diff --git a/archivers/libarchive/files/cpio/test/test_option_L_upper.c b/archivers/libarchive/files/cpio/test/test_option_L_upper.c
index 1774343f673..cab41b61d74 100644
--- a/archivers/libarchive/files/cpio/test/test_option_L_upper.c
+++ b/archivers/libarchive/files/cpio/test/test_option_L_upper.c
@@ -30,8 +30,10 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_L.c,v 1.2 2008/08/24 06:21
* tests won't run on Windows. */
#if defined(_WIN32) && !defined(__CYGWIN__)
#define CAT "type"
+#define SEP "\\"
#else
#define CAT "cat"
+#define SEP "/"
#endif
DEFINE_TEST(test_option_L_upper)
@@ -51,7 +53,7 @@ DEFINE_TEST(test_option_L_upper)
fprintf(filelist, "file\n");
/* Symlink to above file. */
- assertMakeSymlink("symlink", "file");
+ assertMakeSymlink("symlink", "file", 0);
fprintf(filelist, "symlink\n");
fclose(filelist);
@@ -61,7 +63,7 @@ DEFINE_TEST(test_option_L_upper)
assertTextFileContents("1 block\n", "copy.err");
failure("Regular -p without -L should preserve symlinks.");
- assertIsSymlink("copy/symlink", NULL);
+ assertIsSymlink("copy/symlink", NULL, 0);
r = systemf(CAT " filelist | %s -pd -L copy-L >copy-L.out 2>copy-L.err", testprog);
assertEqualInt(r, 0);
@@ -77,13 +79,14 @@ DEFINE_TEST(test_option_L_upper)
assertMakeDir("unpack", 0755);
assertChdir("unpack");
- r = systemf(CAT " ../archive.out | %s -i >unpack.out 2>unpack.err", testprog);
+ r = systemf(CAT " .." SEP "archive.out | %s -i >unpack.out 2>unpack.err", testprog);
+
failure("Error invoking %s -i", testprog);
assertEqualInt(r, 0);
assertTextFileContents("1 block\n", "unpack.err");
assertChdir("..");
- assertIsSymlink("unpack/symlink", NULL);
+ assertIsSymlink("unpack/symlink", NULL, 0);
r = systemf(CAT " filelist | %s -oL >archive-L.out 2>archive-L.err", testprog);
failure("Error invoking %s -oL", testprog);
@@ -92,7 +95,8 @@ DEFINE_TEST(test_option_L_upper)
assertMakeDir("unpack-L", 0755);
assertChdir("unpack-L");
- r = systemf(CAT " ../archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog);
+ r = systemf(CAT " .." SEP "archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog);
+
failure("Error invoking %s -i < archive-L.out", testprog);
assertEqualInt(r, 0);
assertTextFileContents("1 block\n", "unpack-L.err");
diff --git a/archivers/libarchive/files/cpio/test/test_option_a.c b/archivers/libarchive/files/cpio/test/test_option_a.c
index 296387777cc..e96bdf3cab5 100644
--- a/archivers/libarchive/files/cpio/test/test_option_a.c
+++ b/archivers/libarchive/files/cpio/test/test_option_a.c
@@ -71,8 +71,13 @@ test_create(void)
* #ifdef this section out. Most of the test below is
* still valid. */
memset(&times, 0, sizeof(times));
+#if defined(_WIN32) && !defined(CYGWIN)
+ times.actime = 86400;
+ times.modtime = 86400;
+#else
times.actime = 1;
times.modtime = 3;
+#endif
assertEqualInt(0, utime(files[i].name, &times));
/* Record whatever atime the file ended up with. */
diff --git a/archivers/libarchive/files/cpio/test/test_option_c.c b/archivers/libarchive/files/cpio/test/test_option_c.c
index fa47b7e277d..013caed5603 100644
--- a/archivers/libarchive/files/cpio/test/test_option_c.c
+++ b/archivers/libarchive/files/cpio/test/test_option_c.c
@@ -85,7 +85,7 @@ DEFINE_TEST(test_option_c)
/* "symlink" */
if (canSymlink()) {
- assertMakeSymlink("symlink", "file");
+ assertMakeSymlink("symlink", "file", 0);
fprintf(filelist, "symlink\n");
}
diff --git a/archivers/libarchive/files/cpio/test/test_option_t.c b/archivers/libarchive/files/cpio/test/test_option_t.c
index 6bcaee3c87c..eaa73fa3a01 100644
--- a/archivers/libarchive/files/cpio/test/test_option_t.c
+++ b/archivers/libarchive/files/cpio/test/test_option_t.c
@@ -88,11 +88,11 @@ DEFINE_TEST(test_option_t)
setlocale(LC_ALL, "");
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
- strftime(date2, sizeof(date), "%b %d %Y", localtime(&mtime));
- _snprintf(date, sizeof(date)-1, "%12s file", date2);
+ strftime(date2, sizeof(date2)-1, "%b %d %Y", localtime(&mtime));
+ _snprintf(date, sizeof(date)-1, "%12.12s file", date2);
#else
- strftime(date2, sizeof(date), "%b %e %Y", localtime(&mtime));
- snprintf(date, sizeof(date)-1, "%12s file", date2);
+ strftime(date2, sizeof(date2)-1, "%b %e %Y", localtime(&mtime));
+ snprintf(date, sizeof(date)-1, "%12.12s file", date2);
#endif
assertEqualMem(p + 42, date, strlen(date));
free(p);