summaryrefslogtreecommitdiff
path: root/tar
diff options
context:
space:
mode:
authorngie <yaneurabeya@users.noreply.github.com>2017-01-16 18:14:31 -0800
committerGitHub <noreply@github.com>2017-01-16 18:14:31 -0800
commit787a16d61961e3120ffa59443619f371fd8055c3 (patch)
treec18dc10df5b870bfe924546a5e427e8fd9d8b3dc /tar
parent6f58462f7a46bf6fea91f6a0bd38dbc94c288c44 (diff)
parentf8e2a7b40d6dbf15f03f0c1952cc370feceec91b (diff)
downloadlibarchive-787a16d61961e3120ffa59443619f371fd8055c3.tar.gz
Merge branch 'master' into tar-coverity-fixes
Diffstat (limited to 'tar')
-rw-r--r--tar/read.c10
-rw-r--r--tar/test/test_option_uid_uname.c8
-rw-r--r--tar/write.c19
3 files changed, 19 insertions, 18 deletions
diff --git a/tar/read.c b/tar/read.c
index 15425dc0..3c6cb0c1 100644
--- a/tar/read.c
+++ b/tar/read.c
@@ -188,17 +188,17 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
reader_options = getenv(ENV_READER_OPTIONS);
if (reader_options != NULL) {
+ size_t module_len = sizeof(IGNORE_WRONG_MODULE_NAME) - 1;
+ size_t opt_len = strlen(reader_options) + 1;
char *p;
/* Set default read options. */
- p = (char *)malloc(sizeof(IGNORE_WRONG_MODULE_NAME)
- + strlen(reader_options) + 1);
- if (p == NULL)
+ if ((p = malloc(module_len + opt_len)) == NULL)
lafe_errc(1, errno, "Out of memory");
/* Prepend magic code to ignore options for
* a format or modules which are not added to
* the archive read object. */
- sprintf(p, "%s%s", IGNORE_WRONG_MODULE_NAME,
- reader_options);
+ memcpy(p, IGNORE_WRONG_MODULE_NAME, module_len);
+ memcpy(p + module_len, reader_options, opt_len);
r = archive_read_set_options(a, p);
free(p);
if (r == ARCHIVE_FATAL)
diff --git a/tar/test/test_option_uid_uname.c b/tar/test/test_option_uid_uname.c
index 0a8a9bb2..80c06196 100644
--- a/tar/test/test_option_uid_uname.c
+++ b/tar/test/test_option_uid_uname.c
@@ -45,25 +45,25 @@ DEFINE_TEST(test_option_uid_uname)
/* Again with both --uid and --uname */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
- systemf("%s cf archive2 --uid=17 --uname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt",
+ systemf("%s cf archive2 --uid=65123 --uname=foofoofoo --format=ustar file >stdout2.txt 2>stderr2.txt",
testprog));
assertEmptyFile("stdout2.txt");
assertEmptyFile("stderr2.txt");
data = slurpfile(&s, "archive2");
/* Should force uid and uname fields in ustar header. */
- assertEqualMem(data + 108, "000021 \0", 8);
+ assertEqualMem(data + 108, "177143 \0", 8);
assertEqualMem(data + 265, "foofoofoo\0", 10);
free(data);
/* Again with just --uid */
failure("Error invoking %s c", testprog);
assertEqualInt(0,
- systemf("%s cf archive3 --uid=17 --format=ustar file >stdout3.txt 2>stderr3.txt",
+ systemf("%s cf archive3 --uid=65123 --format=ustar file >stdout3.txt 2>stderr3.txt",
testprog));
assertEmptyFile("stdout3.txt");
assertEmptyFile("stderr3.txt");
data = slurpfile(&s, "archive3");
- assertEqualMem(data + 108, "000021 \0", 8);
+ assertEqualMem(data + 108, "177143 \0", 8);
/* Uname field in ustar header should be empty. */
assertEqualMem(data + 265, "\0", 1);
free(data);
diff --git a/tar/write.c b/tar/write.c
index d9ca4d8f..fb8bb92b 100644
--- a/tar/write.c
+++ b/tar/write.c
@@ -145,17 +145,17 @@ set_writer_options(struct bsdtar *bsdtar, struct archive *a)
writer_options = getenv(ENV_WRITER_OPTIONS);
if (writer_options != NULL) {
+ size_t module_len = sizeof(IGNORE_WRONG_MODULE_NAME) - 1;
+ size_t opt_len = strlen(writer_options) + 1;
char *p;
/* Set default write options. */
- p = malloc(sizeof(IGNORE_WRONG_MODULE_NAME)
- + strlen(writer_options) + 1);
- if (p == NULL)
+ if ((p = malloc(module_len + opt_len)) == NULL)
lafe_errc(1, errno, "Out of memory");
/* Prepend magic code to ignore options for
* a format or filters which are not added to
* the archive write object. */
- sprintf(p, "%s%s", IGNORE_WRONG_MODULE_NAME,
- writer_options);
+ memcpy(p, IGNORE_WRONG_MODULE_NAME, module_len);
+ memcpy(p, writer_options, opt_len);
r = archive_write_set_options(a, p);
free(p);
if (r < ARCHIVE_WARN)
@@ -177,17 +177,18 @@ set_reader_options(struct bsdtar *bsdtar, struct archive *a)
reader_options = getenv(ENV_READER_OPTIONS);
if (reader_options != NULL) {
+ size_t module_len = sizeof(IGNORE_WRONG_MODULE_NAME) - 1;
+ size_t opt_len = strlen(reader_options) + 1;
char *p;
/* Set default write options. */
- p = malloc(sizeof(IGNORE_WRONG_MODULE_NAME)
- + strlen(reader_options) + 1);
+ if ((p = malloc(module_len + opt_len)) == NULL)
if (p == NULL)
lafe_errc(1, errno, "Out of memory");
/* Prepend magic code to ignore options for
* a format or filters which are not added to
* the archive write object. */
- sprintf(p, "%s%s", IGNORE_WRONG_MODULE_NAME,
- reader_options);
+ memcpy(p, IGNORE_WRONG_MODULE_NAME, module_len);
+ memcpy(p, reader_options, opt_len);
r = archive_read_set_options(a, p);
free(p);
if (r < ARCHIVE_WARN)