diff options
author | Ngie Cooper <yanegomi@gmail.com> | 2016-12-12 19:57:24 -0800 |
---|---|---|
committer | Ngie Cooper <yanegomi@gmail.com> | 2016-12-13 20:09:36 -0800 |
commit | 6f58462f7a46bf6fea91f6a0bd38dbc94c288c44 (patch) | |
tree | f3ae112aaff26740aba005767197095565110c41 /tar | |
parent | b7b12fad8d80133a2aef6a72e4abc3439e6c6ec9 (diff) | |
download | libarchive-6f58462f7a46bf6fea91f6a0bd38dbc94c288c44.tar.gz |
Use malloc + sprintf instead of malloc + strncpy + strcpy
This will mute a `BUFFER_SIZE` complaint from Coverity and
simplifies the code.
Reported by: Coverity
CID: 1009672-1009674
Diffstat (limited to 'tar')
-rw-r--r-- | tar/read.c | 5 | ||||
-rw-r--r-- | tar/write.c | 10 |
2 files changed, 6 insertions, 9 deletions
@@ -197,9 +197,8 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer) /* Prepend magic code to ignore options for * a format or modules which are not added to * the archive read object. */ - strncpy(p, IGNORE_WRONG_MODULE_NAME, - sizeof(IGNORE_WRONG_MODULE_NAME) -1); - strcpy(p + sizeof(IGNORE_WRONG_MODULE_NAME) -1, reader_options); + sprintf(p, "%s%s", IGNORE_WRONG_MODULE_NAME, + reader_options); r = archive_read_set_options(a, p); free(p); if (r == ARCHIVE_FATAL) diff --git a/tar/write.c b/tar/write.c index 7960487f..d9ca4d8f 100644 --- a/tar/write.c +++ b/tar/write.c @@ -154,9 +154,8 @@ set_writer_options(struct bsdtar *bsdtar, struct archive *a) /* Prepend magic code to ignore options for * a format or filters which are not added to * the archive write object. */ - strncpy(p, IGNORE_WRONG_MODULE_NAME, - sizeof(IGNORE_WRONG_MODULE_NAME) -1); - strcpy(p + sizeof(IGNORE_WRONG_MODULE_NAME) -1, writer_options); + sprintf(p, "%s%s", IGNORE_WRONG_MODULE_NAME, + writer_options); r = archive_write_set_options(a, p); free(p); if (r < ARCHIVE_WARN) @@ -187,9 +186,8 @@ set_reader_options(struct bsdtar *bsdtar, struct archive *a) /* Prepend magic code to ignore options for * a format or filters which are not added to * the archive write object. */ - strncpy(p, IGNORE_WRONG_MODULE_NAME, - sizeof(IGNORE_WRONG_MODULE_NAME) -1); - strcpy(p + sizeof(IGNORE_WRONG_MODULE_NAME) -1, reader_options); + sprintf(p, "%s%s", IGNORE_WRONG_MODULE_NAME, + reader_options); r = archive_read_set_options(a, p); free(p); if (r < ARCHIVE_WARN) |