mirror of
https://github.com/facebook/zstd.git
synced 2025-08-05 19:15:58 +03:00
[fuzz] Fix regression_driver.c with directory input (#1944)
The `numFiles` variable wasn't updated, so the fuzzer didn't do anything. I did two things to fix this: 1. Remove the `numFiles` variable entirely. 2. Error if we can't open a file and print the number of files tested.
This commit is contained in:
@@ -20,23 +20,28 @@ int main(int argc, char const **argv) {
|
|||||||
int const kFollowLinks = 1;
|
int const kFollowLinks = 1;
|
||||||
FileNamesTable* files;
|
FileNamesTable* files;
|
||||||
const char** const fnTable = argv + 1;
|
const char** const fnTable = argv + 1;
|
||||||
unsigned numFiles = (unsigned)(argc - 1);
|
|
||||||
uint8_t *buffer = NULL;
|
uint8_t *buffer = NULL;
|
||||||
size_t bufferSize = 0;
|
size_t bufferSize = 0;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
int ret;
|
unsigned numFilesTested = 0;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
unsigned const numFiles = (unsigned)(argc - 1);
|
||||||
#ifdef UTIL_HAS_CREATEFILELIST
|
#ifdef UTIL_HAS_CREATEFILELIST
|
||||||
files = UTIL_createExpandedFNT(fnTable, numFiles, kFollowLinks);
|
files = UTIL_createExpandedFNT(fnTable, numFiles, kFollowLinks);
|
||||||
if (!files) numFiles = 0;
|
|
||||||
#else
|
#else
|
||||||
files = UTIL_createFNT_fromROTable(fnTable, numFiles);
|
files = UTIL_createFNT_fromROTable(fnTable, numFiles);
|
||||||
if (!files) numFiles = 0;
|
assert(numFiles == files->tableSize);
|
||||||
assert(numFiles == files->tableSize);
|
|
||||||
#endif
|
#endif
|
||||||
if (numFiles == 0)
|
}
|
||||||
|
if (!files) {
|
||||||
|
fprintf(stderr, "ERROR: Failed to create file names table\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (files->tableSize == 0)
|
||||||
fprintf(stderr, "WARNING: No files passed to %s\n", argv[0]);
|
fprintf(stderr, "WARNING: No files passed to %s\n", argv[0]);
|
||||||
for (i = 0; i < numFiles; ++i) {
|
for (i = 0; i < files->tableSize; ++i) {
|
||||||
char const *fileName = files->fileNames[i];
|
char const *fileName = files->fileNames[i];
|
||||||
DEBUGLOG(3, "Running %s", fileName);
|
DEBUGLOG(3, "Running %s", fileName);
|
||||||
size_t const fileSize = UTIL_getFileSize(fileName);
|
size_t const fileSize = UTIL_getFileSize(fileName);
|
||||||
@@ -45,9 +50,10 @@ int main(int argc, char const **argv) {
|
|||||||
|
|
||||||
/* Check that it is a regular file, and that the fileSize is valid.
|
/* Check that it is a regular file, and that the fileSize is valid.
|
||||||
* If it is not a regular file, then it may have been deleted since we
|
* If it is not a regular file, then it may have been deleted since we
|
||||||
* constructed the list, so just skip it.
|
* constructed the list, so just skip it, but return an error exit code.
|
||||||
*/
|
*/
|
||||||
if (!UTIL_isRegularFile(fileName)) {
|
if (!UTIL_isRegularFile(fileName)) {
|
||||||
|
ret = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
FUZZ_ASSERT_MSG(fileSize <= kMaxFileSize, fileName);
|
FUZZ_ASSERT_MSG(fileSize <= kMaxFileSize, fileName);
|
||||||
@@ -68,9 +74,14 @@ int main(int argc, char const **argv) {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
/* Run the fuzz target */
|
/* Run the fuzz target */
|
||||||
LLVMFuzzerTestOneInput(buffer, fileSize);
|
LLVMFuzzerTestOneInput(buffer, fileSize);
|
||||||
|
++numFilesTested;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "Tested %u files: ", numFilesTested);
|
||||||
|
if (ret == 0) {
|
||||||
|
fprintf(stderr, "Success!\n");
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Failure!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
UTIL_freeFileNamesTable(files);
|
UTIL_freeFileNamesTable(files);
|
||||||
return ret;
|
return ret;
|
||||||
|
Reference in New Issue
Block a user