diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /tools/fuzzing/interface/FuzzingInterface.h | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/fuzzing/interface/FuzzingInterface.h')
-rw-r--r-- | tools/fuzzing/interface/FuzzingInterface.h | 48 |
1 files changed, 4 insertions, 44 deletions
diff --git a/tools/fuzzing/interface/FuzzingInterface.h b/tools/fuzzing/interface/FuzzingInterface.h index 792f0809ec..31a4b50867 100644 --- a/tools/fuzzing/interface/FuzzingInterface.h +++ b/tools/fuzzing/interface/FuzzingInterface.h @@ -37,55 +37,17 @@ extern LazyLogModule gFuzzingLog; MOZ_LOG(mozilla::gFuzzingLog, mozilla::LogLevel::Verbose, args) #endif // JS_STANDALONE +} // namespace mozilla + typedef int (*FuzzingTestFuncRaw)(const uint8_t*, size_t); #ifdef AFLFUZZ -static int afl_interface_raw(const char* testFile, - FuzzingTestFuncRaw testFunc) { - char* buf = NULL; - - while (__AFL_LOOP(1000)) { - std::ifstream is; - is.open(testFile, std::ios::binary); - is.seekg(0, std::ios::end); - int len = is.tellg(); - is.seekg(0, std::ios::beg); - MOZ_RELEASE_ASSERT(len >= 0); - if (!len) { - is.close(); - continue; - } - buf = (char*)realloc(buf, len); - MOZ_RELEASE_ASSERT(buf); - is.read(buf, len); - is.close(); - testFunc((uint8_t*)buf, (size_t)len); - } - - free(buf); - - return 0; -} - -# define MOZ_AFL_INTERFACE_COMMON() \ - char* testFilePtr = getenv("MOZ_FUZZ_TESTFILE"); \ - if (!testFilePtr) { \ - fprintf(stderr, \ - "Must specify testfile in MOZ_FUZZ_TESTFILE environment " \ - "variable.\n"); \ - return 1; \ - } \ - /* Make a copy of testFilePtr so the testing function can safely call \ - * getenv \ - */ \ - std::string testFile(testFilePtr); +int afl_interface_raw(FuzzingTestFuncRaw testFunc); # define MOZ_AFL_INTERFACE_RAW(initFunc, testFunc, moduleName) \ static int afl_fuzz_##moduleName(const uint8_t* data, size_t size) { \ - MOZ_RELEASE_ASSERT(data == NULL && size == 0); \ - MOZ_AFL_INTERFACE_COMMON(); \ - return ::mozilla::afl_interface_raw(testFile.c_str(), testFunc); \ + return afl_interface_raw(testFunc); \ } \ static void __attribute__((constructor)) AFLRegister##moduleName() { \ ::mozilla::FuzzerRegistry::getInstance().registerModule( \ @@ -110,6 +72,4 @@ static int afl_interface_raw(const char* testFile, MOZ_LIBFUZZER_INTERFACE_RAW(initFunc, testFunc, moduleName); \ MOZ_AFL_INTERFACE_RAW(initFunc, testFunc, moduleName); -} // namespace mozilla - #endif // FuzzingInterface_h__ |