]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fixed unsafe string copy and concat in `fileio.c`. 1290/head
authorEden Zik <ezik@fb.com>
Tue, 21 Aug 2018 02:15:24 +0000 (22:15 -0400)
committerEden Zik <ezik@fb.com>
Tue, 21 Aug 2018 02:15:24 +0000 (22:15 -0400)
Per warnings from flawfinder: "Does not check for buffer overflows when
copying to destination [MS-banned] (CWE-120). Consider using snprintf,
strcpy_s, or strlcpy (warning: strncpy easily misused).".

Replaced called to strcpy and strcat in `fileio.c` to calls with a
specified size (`strncpy` and `strncat`).

Tested the changes on OSX, Linux, Windows.
On OSX + Linux, changes were tested with ASAN. The following flags were
used: 'check_initialization_order=1:strict_init_order=1:detect_odr_violation=1:detect_stack_use_after_return=1'

To reproduce warning:
./flawfinder.py ./programs/fileio.c

programs/fileio.c
tests/.gitignore

index 39b2c741c8e90202e0f6ebba74a58fe7709cc22e..5f10958d754e71bcb732985c8dfead7d17511acd 100644 (file)
@@ -1011,8 +1011,8 @@ int FIO_compressMultipleFilenames(const char** inFileNamesTable, unsigned nbFile
                 if (!dstFileName) {
                     EXM_THROW(30, "zstd: %s", strerror(errno));
             }   }
-            strcpy(dstFileName, inFileNamesTable[u]);
-            strcat(dstFileName, suffix);
+            strncpy(dstFileName, inFileNamesTable[u], ifnSize+1 /* Include null */);
+            strncat(dstFileName, suffix, suffixSize);
             missed_files += FIO_compressFilename_dstFile(ress, dstFileName, inFileNamesTable[u], compressionLevel);
     }   }
 
index 4911b2d62a568dcf446cfd45352fe068f5c1b4c2..da536251dd3eb31b2328bdd3ae3951fa2e7a95e1 100644 (file)
@@ -26,6 +26,7 @@ invalidDictionaries
 checkTag
 zcat
 zstdcat
+tm
 
 # Tmp test directory
 zstdtest