Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/fuzzing/Progmasoft
diff options
context:
space:
mode:
authorLeitwolf2026-10-24 19:03:40 +0300
committerGitHub2026-10-24 19:03:40 +0300
commit4f1c759cffcb14bd6511e1d7c5fbace682e24f2d (patch)
tree415fe5d48a5b48650bba3747beaf245d727c4f61 /fuzzing/Progmasoft
parent83c6fc3ac13abe83fa39f7b5f8559ccaf4412233 (diff)
parent622188f9c08e4af35941c146979883ed4882410e (diff)
downloadcatch3-4f1c759cffcb14bd6511e1d7c5fbace682e24f2d.tar.gz
Merge pull request #15 from Progmasoft/feature/catch3-runner
Replace Catch2's runner with the Catch3 runner
Diffstat (limited to 'fuzzing/Progmasoft')
-rw-r--r--fuzzing/Progmasoft/fuzz_RunnerJson.cpp29
-rw-r--r--fuzzing/Progmasoft/fuzz_RunnerOptions.cpp50
2 files changed, 79 insertions, 0 deletions
diff --git a/fuzzing/Progmasoft/fuzz_RunnerJson.cpp b/fuzzing/Progmasoft/fuzz_RunnerJson.cpp
new file mode 100644
index 00000000..4cc3770c
--- /dev/null
+++ b/fuzzing/Progmasoft/fuzz_RunnerJson.cpp
@@ -0,0 +1,29 @@
+// Copyright (c) 2026 Progmasoft.
+// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1
+
+// The runner reads JSON from its workers, from history files and from
+// reports; none of them may crash it. A document that parses must also
+// print and parse back to the same text.
+
+#include <Progmasoft/Runner/Json.hpp>
+
+#include <cstdint>
+#include <cstdlib>
+#include <string_view>
+
+extern "C" int
+LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size)
+{
+ const std::string_view text{reinterpret_cast<const char *>(data), size};
+ auto parsed = Progmasoft::Catch3::Runner::ParseJson(text);
+ if (parsed)
+ {
+ const auto printed = parsed->ToString();
+ auto again = Progmasoft::Catch3::Runner::ParseJson(printed);
+ if (!again || again->ToString() != printed)
+ {
+ std::abort();
+ }
+ }
+ return 0;
+}
diff --git a/fuzzing/Progmasoft/fuzz_RunnerOptions.cpp b/fuzzing/Progmasoft/fuzz_RunnerOptions.cpp
new file mode 100644
index 00000000..2a10ba91
--- /dev/null
+++ b/fuzzing/Progmasoft/fuzz_RunnerOptions.cpp
@@ -0,0 +1,50 @@
+// Copyright (c) 2026 Progmasoft.
+// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1
+
+// The command line of a test binary: arguments separated by NUL bytes. The
+// parser must answer with options or an error, never crash, and the worker
+// arguments it derives must parse again.
+
+#include <Progmasoft/Runner/Options.hpp>
+
+#include <cstdint>
+#include <cstdlib>
+#include <string>
+#include <vector>
+
+extern "C" int
+LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size)
+{
+ std::vector<std::string> arguments(1);
+ for (std::size_t index = 0; index < size; ++index)
+ {
+ if (data[index] == 0)
+ {
+ arguments.emplace_back();
+ }
+ else
+ {
+ arguments.back().push_back(static_cast<char>(data[index]));
+ }
+ }
+ // Reading a file named by --input-file is not what is fuzzed here.
+ for (const auto &argument : arguments)
+ {
+ if (argument.find("input-file") != std::string::npos ||
+ (argument.size() >= 2 && argument[0] == '-' && argument[1] == 'f'))
+ {
+ return 0;
+ }
+ }
+ auto options = Progmasoft::Catch3::Runner::ParseOptions(arguments);
+ if (options)
+ {
+ const auto worker = Progmasoft::Catch3::Runner::ParseOptions(
+ Progmasoft::Catch3::Runner::WorkerArguments(*options));
+ if (!worker)
+ {
+ std::abort();
+ }
+ }
+ return 0;
+}