]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
tests: silence CodeQL warning in tar/test_option_b
authorMartin Matuska <martin@matuska.de>
Wed, 7 Dec 2022 14:59:14 +0000 (15:59 +0100)
committerMartin Matuska <martin@matuska.de>
Wed, 7 Dec 2022 15:01:26 +0000 (16:01 +0100)
Use strncpy() and strncat() instead of strcpy() and strcat()

tar/test/test_option_b.c

index 0eee80d86f498aa142933c9caf244448f2e871df..d1b75e35061305fc89fa735ad1e8cd9fbebe0c6c 100644 (file)
@@ -30,15 +30,17 @@ __FBSDID("$FreeBSD$");
 DEFINE_TEST(test_option_b)
 {
        char *testprog_ustar;
+       size_t testprog_ustar_len;
 
        assertMakeFile("file1", 0644, "file1");
        if (systemf("cat file1 > test_cat.out 2> test_cat.err") != 0) {
                skipping("This test requires a `cat` program");
                return;
        }
-       testprog_ustar = malloc(strlen(testprog) + sizeof(USTAR_OPT) + 1);
-       strcpy(testprog_ustar, testprog);
-       strcat(testprog_ustar, USTAR_OPT);
+       testprog_ustar_len = strlen(testprog) + sizeof(USTAR_OPT) + 1;
+       testprog_ustar = malloc(testprog_ustar_len);
+       strncpy(testprog_ustar, testprog, testprog_ustar_len);
+       strncat(testprog_ustar, USTAR_OPT, testprog_ustar_len);
 
        /*
         * Bsdtar does not pad if the output is going directly to a disk file.