-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing: Add basic fuzz test harnesses
- Loading branch information
1 parent
2d161c5
commit 333c79c
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Determine the flags for fuzzing. Use OSS-Fuzz's configuration if available, otherwise fall back to defaults. | ||
if(DEFINED ENV{LIB_FUZZING_ENGINE}) | ||
set(FUZZING_ENGINE $ENV{LIB_FUZZING_ENGINE}) | ||
set(FUZZING_COMPILE_FLAGS "") | ||
set(FUZZING_LINK_FLAGS "${FUZZING_ENGINE}") | ||
else() | ||
set(FUZZING_COMPILE_FLAGS "-fsanitize=fuzzer") | ||
set(FUZZING_LINK_FLAGS "-fsanitize=fuzzer") | ||
endif() | ||
|
||
# Define the fuzz target | ||
add_executable(DateParserFuzzer dateparserfuzzer.cpp) | ||
|
||
# Apply the determined flags | ||
set_target_properties(DateParserFuzzer PROPERTIES | ||
COMPILE_FLAGS "${FUZZING_COMPILE_FLAGS}" | ||
LINK_FLAGS "${FUZZING_LINK_FLAGS}" | ||
) | ||
|
||
# Link QuantLib and any other necessary libraries | ||
target_link_libraries(DateParserFuzzer ql_library ${QL_THREAD_LIBRARIES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <ql/time/asx.hpp> | ||
#include <ql/time/date.hpp> | ||
#include <ql/time/ecb.hpp> | ||
#include <ql/time/imm.hpp> | ||
#include <ql/time/timeunit.hpp> | ||
#include <ql/utilities/dataparsers.hpp> | ||
#include <string> | ||
|
||
#ifndef __clang__ | ||
#pragma message("Fuzzer headers are available from clang, other compilers have not been tested.") | ||
#endif | ||
#include <fuzzer/FuzzedDataProvider.h> | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | ||
FuzzedDataProvider fdp(data, size); | ||
constexpr int kMaxString = 100; | ||
try { | ||
(void)QuantLib::DateParser::parseFormatted(fdp.ConsumeRandomLengthString(kMaxString), "%Y-%m-%d"); | ||
(void)QuantLib::DateParser::parseISO(fdp.ConsumeRandomLengthString(kMaxString)); | ||
} catch (const std::exception& e) { | ||
// Handle or ignore exceptions | ||
} | ||
return 0; | ||
} |