aboutsummaryrefslogtreecommitdiffstats
path: root/cpio
diff options
context:
space:
mode:
Diffstat (limited to 'cpio')
-rw-r--r--cpio/cpio.c13
-rw-r--r--cpio/test/test_option_Z_upper.c5
-rw-r--r--cpio/test/test_option_a.c3
-rw-r--r--cpio/test/test_option_b64encode.c2
-rw-r--r--cpio/test/test_option_grzip.c3
-rw-r--r--cpio/test/test_option_lrzip.c3
-rw-r--r--cpio/test/test_option_lz4.c7
-rw-r--r--cpio/test/test_option_lzma.c4
-rw-r--r--cpio/test/test_option_lzop.c3
-rw-r--r--cpio/test/test_option_uuencode.c2
-rw-r--r--cpio/test/test_option_xz.c4
-rw-r--r--cpio/test/test_option_y.c6
-rw-r--r--cpio/test/test_option_z.c3
13 files changed, 43 insertions, 15 deletions
diff --git a/cpio/cpio.c b/cpio/cpio.c
index 1691c756599e..5beedd0d16bc 100644
--- a/cpio/cpio.c
+++ b/cpio/cpio.c
@@ -628,6 +628,7 @@ mode_out(struct cpio *cpio)
blocks == 1 ? "block" : "blocks");
}
archive_write_free(cpio->archive);
+ archive_entry_linkresolver_free(cpio->linkresolver);
}
static const char *
@@ -1194,12 +1195,15 @@ mode_pass(struct cpio *cpio, const char *destdir)
struct lafe_line_reader *lr;
const char *p;
int r;
+ size_t destdir_len;
/* Ensure target dir has a trailing '/' to simplify path surgery. */
- cpio->destdir = malloc(strlen(destdir) + 8);
- strcpy(cpio->destdir, destdir);
- if (destdir[strlen(destdir) - 1] != '/')
- strcat(cpio->destdir, "/");
+ destdir_len = strlen(destdir);
+ cpio->destdir = malloc(destdir_len + 8);
+ memcpy(cpio->destdir, destdir, destdir_len);
+ if (destdir_len == 0 || destdir[destdir_len - 1] != '/')
+ cpio->destdir[destdir_len++] = '/';
+ cpio->destdir[destdir_len++] = '\0';
cpio->archive = archive_write_disk_new();
if (cpio->archive == NULL)
@@ -1240,6 +1244,7 @@ mode_pass(struct cpio *cpio, const char *destdir)
}
archive_write_free(cpio->archive);
+ free(cpio->pass_destpath);
}
/*
diff --git a/cpio/test/test_option_Z_upper.c b/cpio/test/test_option_Z_upper.c
index d69a85ea58ae..ff388427e372 100644
--- a/cpio/test/test_option_Z_upper.c
+++ b/cpio/test/test_option_Z_upper.c
@@ -43,17 +43,18 @@ DEFINE_TEST(test_option_Z_upper)
if (strstr(p, "compression not available") != NULL) {
skipping("This version of bsdcpio was compiled "
"without compress support");
+ free(p);
return;
}
failure("-Z option is broken");
assertEqualInt(r, 0);
- goto done;
+ free(p);
+ return;
}
free(p);
/* Check that the archive file has a compress signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\x1f\x9d", 2);
-done:
free(p);
}
diff --git a/cpio/test/test_option_a.c b/cpio/test/test_option_a.c
index 606de606e2c5..296387777ccf 100644
--- a/cpio/test/test_option_a.c
+++ b/cpio/test/test_option_a.c
@@ -96,7 +96,8 @@ DEFINE_TEST(test_option_a)
test_create();
/* Sanity check; verify that atimes really do get modified. */
- assert((p = slurpfile(NULL, "f0")) != NULL);
+ p = slurpfile(NULL, "f0");
+ assert(p != NULL);
free(p);
assertEqualInt(0, stat("f0", &st));
if (st.st_atime == files[0].atime_sec) {
diff --git a/cpio/test/test_option_b64encode.c b/cpio/test/test_option_b64encode.c
index 8f6b4157c01c..7c15a8230606 100644
--- a/cpio/test/test_option_b64encode.c
+++ b/cpio/test/test_option_b64encode.c
@@ -42,6 +42,7 @@ DEFINE_TEST(test_option_b64encode)
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "begin-base64 644", 16);
+ free(p);
/* Archive it with uuencode only. */
assertEqualInt(0,
@@ -51,4 +52,5 @@ DEFINE_TEST(test_option_b64encode)
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "begin-base64 644", 16);
+ free(p);
}
diff --git a/cpio/test/test_option_grzip.c b/cpio/test/test_option_grzip.c
index dfce2e064e07..7e7dd2c8e6f3 100644
--- a/cpio/test/test_option_grzip.c
+++ b/cpio/test/test_option_grzip.c
@@ -44,9 +44,10 @@ DEFINE_TEST(test_option_grzip)
systemf("echo f | %s -o --grzip >archive.out 2>archive.err",
testprog));
p = slurpfile(&s, "archive.err");
- p[s] = '\0';
+ free(p);
/* Check that the archive file has an grzip signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "GRZipII\x00\x02\x04:)", 12);
+ free(p);
}
diff --git a/cpio/test/test_option_lrzip.c b/cpio/test/test_option_lrzip.c
index a84f75157a4c..8d9c0d576cc3 100644
--- a/cpio/test/test_option_lrzip.c
+++ b/cpio/test/test_option_lrzip.c
@@ -44,9 +44,10 @@ DEFINE_TEST(test_option_lrzip)
systemf("echo f | %s -o --lrzip >archive.out 2>archive.err",
testprog));
p = slurpfile(&s, "archive.err");
- p[s] = '\0';
+ free(p);
/* Check that the archive file has an lzma signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "LRZI\x00", 5);
+ free(p);
}
diff --git a/cpio/test/test_option_lz4.c b/cpio/test/test_option_lz4.c
index afd683ddc773..88dfbd63bae9 100644
--- a/cpio/test/test_option_lz4.c
+++ b/cpio/test/test_option_lz4.c
@@ -43,6 +43,7 @@ DEFINE_TEST(test_option_lz4)
if (strstr(p, "compression not available") != NULL) {
skipping("This version of bsdcpio was compiled "
"without lz4 support");
+ free(p);
return;
}
/* POSIX permits different handling of the spawnp
@@ -52,6 +53,7 @@ DEFINE_TEST(test_option_lz4)
if (strstr(p, "Can't launch") != NULL && !canLz4()) {
skipping("This version of bsdcpio uses an external lz4 program "
"but no such program is available on this system.");
+ free(p);
return;
}
/* Some systems successfully spawn the new process,
@@ -61,6 +63,7 @@ DEFINE_TEST(test_option_lz4)
if (strstr(p, "Can't write") != NULL && !canLz4()) {
skipping("This version of bsdcpio uses an external lz4 program "
"but no such program is available on this system.");
+ free(p);
return;
}
/* On some systems the error won't be detected until closing
@@ -68,14 +71,18 @@ DEFINE_TEST(test_option_lz4)
if (strstr(p, "Error closing") != NULL && !canLz4()) {
skipping("This version of bsdcpio uses an external lz4 program "
"but no such program is available on this system.");
+ free(p);
return;
}
+ free(p);
failure("--lz4 option is broken: %s", p);
assertEqualInt(r, 0);
return;
}
+ free(p);
/* Check that the archive file has an lz4 signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\x04\x22\x4d\x18", 4);
+ free(p);
}
diff --git a/cpio/test/test_option_lzma.c b/cpio/test/test_option_lzma.c
index c6e335301505..b7cad3d1e99a 100644
--- a/cpio/test/test_option_lzma.c
+++ b/cpio/test/test_option_lzma.c
@@ -43,14 +43,18 @@ DEFINE_TEST(test_option_lzma)
if (strstr(p, "compression not available") != NULL) {
skipping("This version of bsdcpio was compiled "
"without lzma support");
+ free(p);
return;
}
failure("--lzma option is broken");
assertEqualInt(r, 0);
+ free(p);
return;
}
+ free(p);
/* Check that the archive file has an lzma signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\x5d\00\00", 3);
+ free(p);
}
diff --git a/cpio/test/test_option_lzop.c b/cpio/test/test_option_lzop.c
index 9f1666e9c5b9..aa40ef5b6392 100644
--- a/cpio/test/test_option_lzop.c
+++ b/cpio/test/test_option_lzop.c
@@ -39,7 +39,7 @@ DEFINE_TEST(test_option_lzop)
r = systemf("echo f | %s -o --lzop >archive.out 2>archive.err",
testprog);
p = slurpfile(&s, "archive.err");
- p[s] = '\0';
+ free(p);
if (r != 0) {
if (!canLzop()) {
skipping("lzop is not supported on this platform");
@@ -53,4 +53,5 @@ DEFINE_TEST(test_option_lzop)
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a", 9);
+ free(p);
}
diff --git a/cpio/test/test_option_uuencode.c b/cpio/test/test_option_uuencode.c
index ecf354f8f391..a42a0e03096f 100644
--- a/cpio/test/test_option_uuencode.c
+++ b/cpio/test/test_option_uuencode.c
@@ -42,6 +42,7 @@ DEFINE_TEST(test_option_uuencode)
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "begin 644", 9);
+ free(p);
/* Archive it with uuencode only. */
assertEqualInt(0,
@@ -51,4 +52,5 @@ DEFINE_TEST(test_option_uuencode)
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "begin 644", 9);
+ free(p);
}
diff --git a/cpio/test/test_option_xz.c b/cpio/test/test_option_xz.c
index 02b5dfaad4a1..f0d3b33d45b8 100644
--- a/cpio/test/test_option_xz.c
+++ b/cpio/test/test_option_xz.c
@@ -44,14 +44,18 @@ DEFINE_TEST(test_option_xz)
if (strstr(p, "compression not available") != NULL) {
skipping("This version of bsdcpio was compiled "
"without xz support");
+ free(p);
return;
}
+ free(p);
failure("--xz option is broken");
assertEqualInt(r, 0);
return;
}
+ free(p);
/* Check that the archive file has an xz signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\xFD\x37\x7A\x58\x5A\x00", 6);
+ free(p);
}
diff --git a/cpio/test/test_option_y.c b/cpio/test/test_option_y.c
index 0397b3d1bf45..989b5f1aaf6e 100644
--- a/cpio/test/test_option_y.c
+++ b/cpio/test/test_option_y.c
@@ -38,7 +38,7 @@ DEFINE_TEST(test_option_y)
r = systemf("echo f | %s -oy >archive.out 2>archive.err",
testprog);
p = slurpfile(&s, "archive.err");
- p[s] = '\0';
+ free(p);
if (r != 0) {
if (!canBzip2()) {
skipping("bzip2 is not supported on this platform");
@@ -46,14 +46,12 @@ DEFINE_TEST(test_option_y)
}
failure("-y option is broken");
assertEqualInt(r, 0);
- goto done;
+ return;
}
assertTextFileContents("1 block\n", "archive.err");
/* Check that the archive file has a bzip2 signature. */
- free(p);
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "BZh9", 4);
-done:
free(p);
}
diff --git a/cpio/test/test_option_z.c b/cpio/test/test_option_z.c
index 0b68a42babbf..803232d045c2 100644
--- a/cpio/test/test_option_z.c
+++ b/cpio/test/test_option_z.c
@@ -38,7 +38,7 @@ DEFINE_TEST(test_option_z)
r = systemf("echo f | %s -oz >archive.out 2>archive.err",
testprog);
p = slurpfile(&s, "archive.err");
- p[s] = '\0';
+ free(p);
if (r != 0) {
if (!canGzip()) {
skipping("gzip is not supported on this platform");
@@ -52,4 +52,5 @@ DEFINE_TEST(test_option_z)
p = slurpfile(&s, "archive.out");
assert(s > 4);
assertEqualMem(p, "\x1f\x8b\x08\x00", 4);
+ free(p);
}