]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use malloc + sprintf instead of malloc + strncpy + strcpy
authorNgie Cooper <yanegomi@gmail.com>
Tue, 13 Dec 2016 03:57:24 +0000 (19:57 -0800)
committerNgie Cooper <yanegomi@gmail.com>
Wed, 14 Dec 2016 04:09:36 +0000 (20:09 -0800)
This will mute a `BUFFER_SIZE` complaint from Coverity and
simplifies the code.

Reported by:    Coverity
CID:            1009672-1009674

tar/read.c
tar/write.c

index e94cb3da8ac704116d2f93ee9f59d36bed8b201c..15425dc08dd0db238868b7f6371d3ed7fc77e928 100644 (file)
@@ -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)
index 7960487f9d067700326d040b7bd45f6a84f1b8a2..d9ca4d8f77a3afcae1f04196651d1fc53e2ad998 100644 (file)
@@ -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)