summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2020-10-05 19:46:18 +0200
committerMax Kellermann <max@musicpd.org>2020-10-05 20:25:26 +0200
commitdffd5831f83e31b7d07962d69922d64131c6880a (patch)
tree0aab38c13ff70859eaa0cbfa0cf6b1e1a9a42bcf /test
parent8358b34efa8489617440ea7bb277d72cc26182f7 (diff)
test/fuzzer: a simple fuzzer using libFuzzer
This commit adds some basic infrastructure for fuzzers, and adds a fuzzer for the CUE sheet parser.
Diffstat (limited to 'test')
-rw-r--r--test/fuzzer/FuzzCueParser.cxx26
-rw-r--r--test/fuzzer/meson.build9
2 files changed, 35 insertions, 0 deletions
diff --git a/test/fuzzer/FuzzCueParser.cxx b/test/fuzzer/FuzzCueParser.cxx
new file mode 100644
index 000000000..912cabf6a
--- /dev/null
+++ b/test/fuzzer/FuzzCueParser.cxx
@@ -0,0 +1,26 @@
+#include "playlist/cue/CueParser.hxx"
+#include "util/IterableSplitString.hxx"
+
+#include <string>
+#include <string_view>
+
+extern "C" {
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
+}
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ CueParser parser;
+
+ const std::string_view src{(const char *)data, size};
+
+ for (const auto line : IterableSplitString(src, '\n')) {
+ parser.Feed(std::string(line).c_str());
+ parser.Get();
+ }
+
+ parser.Finish();
+ parser.Get();
+
+ return 0;
+}
diff --git a/test/fuzzer/meson.build b/test/fuzzer/meson.build
new file mode 100644
index 000000000..6a87f99ea
--- /dev/null
+++ b/test/fuzzer/meson.build
@@ -0,0 +1,9 @@
+executable(
+ 'FuzzCueParser',
+ 'FuzzCueParser.cxx',
+ '../../src/playlist/cue/CueParser.cxx',
+ include_directories: inc,
+ dependencies: [
+ tag_dep,
+ ],
+)