srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/fuzz/fuzz_pcapng_reader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fuzz/fuzz_pcapng_reader.cpp')
-rw-r--r--fuzz/fuzz_pcapng_reader.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/fuzz/fuzz_pcapng_reader.cpp b/fuzz/fuzz_pcapng_reader.cpp
new file mode 100644
index 0000000..e27675b
--- /dev/null
+++ b/fuzz/fuzz_pcapng_reader.cpp
@@ -0,0 +1,21 @@
+#include <cstddef>
+#include <cstdint>
+#include <cstdio>
+
+#include "wireframe/pcapng/reader.hpp"
+
+// Reader parses file/network data that isn't necessarily our own
+// writer's output - a user could point it at any file. fmemopen()
+// gives libFuzzer's byte buffer a FILE* without touching a real file.
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ FILE* file = fmemopen(const_cast<uint8_t*>(data), size, "rb");
+ if (file == nullptr) return 0;
+
+ wireframe::pcapng::Reader reader(file);
+ while (reader.next_packet()) {
+ // keep draining until EOF/malformed-block termination
+ }
+
+ std::fclose(file);
+ return 0;
+}