summaryrefslogtreecommitdiffstats
path: root/standalone_fuzz_target_runner.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 21:14:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 21:14:51 +0000
commitbc282425088455198a7a99511c75914477d4ed32 (patch)
tree1b1fb887a634136a093deea7e4dd95d054201e7a /standalone_fuzz_target_runner.cc
parentReleasing progress-linux version 1.8.3-3~progress7.99u1. (diff)
downloaddnsdist-bc282425088455198a7a99511c75914477d4ed32.tar.xz
dnsdist-bc282425088455198a7a99511c75914477d4ed32.zip
Merging upstream version 1.9.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'standalone_fuzz_target_runner.cc')
-rw-r--r--standalone_fuzz_target_runner.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/standalone_fuzz_target_runner.cc b/standalone_fuzz_target_runner.cc
new file mode 100644
index 0000000..0ca9106
--- /dev/null
+++ b/standalone_fuzz_target_runner.cc
@@ -0,0 +1,52 @@
+#include <cstdint>
+#include <fstream>
+#include <iostream>
+#include <stdexcept>
+#include <sys/stat.h>
+#include <vector>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
+extern "C" __attribute__((weak)) int LLVMFuzzerInitialize(int* argc, char*** argv);
+
+int main(int argc, char** argv)
+{
+ std::cerr<<"StandaloneFuzzTargetMain: running "<<(argc-1)<<" inputs"<<std::endl;
+
+ if (LLVMFuzzerInitialize) {
+ LLVMFuzzerInitialize(&argc, &argv);
+ }
+
+ for (int i = 1; i < argc; i++) {
+
+ struct stat st;
+ if (stat(argv[i], &st) || !S_ISREG(st.st_mode)) {
+ std::cerr<<"Skipping non-regular file: "<<std::string(argv[i])<<std::endl;
+ continue;
+ }
+
+ std::cerr<<"Running: "<<std::string(argv[i])<<std::endl;
+
+ std::ifstream file(argv[i], std::ios::binary);
+ file.seekg(0, std::ios::end);
+ size_t fileSize = file.tellg();
+ file.seekg(0, std::ios::beg);
+
+ std::vector<char> buffer;
+ buffer.resize(fileSize);
+
+ file.read(reinterpret_cast<char*>(buffer.data()), fileSize);
+
+ if (file.fail()) {
+ file.close();
+ throw std::runtime_error("Error reading fuzzing input from file '" + std::string(argv[i]) + '"');
+ }
+
+ file.close();
+
+ LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t*>(buffer.data()), fileSize);
+
+ std::cerr<<"Done: '"<<std::string(argv[i])<<"': ("<<fileSize<<" bytes)"<<std::endl;
+ }
+
+ return 0;
+}