From: Ngie Cooper Date: Tue, 13 Dec 2016 03:57:24 +0000 (-0800) Subject: Use malloc + sprintf instead of malloc + strncpy + strcpy X-Git-Tag: v3.3.0~36^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f58462f7a46bf6fea91f6a0bd38dbc94c288c44;p=thirdparty%2Flibarchive.git 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 --- diff --git a/tar/read.c b/tar/read.c index e94cb3da8..15425dc08 100644 --- a/tar/read.c +++ b/tar/read.c @@ -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 7960487f9..d9ca4d8f7 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)