srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/fuzz/fuzz_checksum.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fuzz/fuzz_checksum.cpp')
-rw-r--r--fuzz/fuzz_checksum.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/fuzz/fuzz_checksum.cpp b/fuzz/fuzz_checksum.cpp
new file mode 100644
index 0000000..f490d1c
--- /dev/null
+++ b/fuzz/fuzz_checksum.cpp
@@ -0,0 +1,27 @@
+#include <cstddef>
+#include <cstdint>
+
+#include "wireframe/net/checksum.hpp"
+#include "wireframe/net/ipv4.hpp"
+
+using namespace wireframe::net;
+
+// internet_checksum() itself takes arbitrary bytes directly. The
+// verify_*_checksum_ipv4() wrappers additionally need two addresses,
+// so the first 8 bytes of input become src/dst and the rest is treated
+// as the header/segment/datagram under test - exercises the
+// pseudo-header construction (detail::build_ipv4_pseudo_header) along
+// with the checksum math itself.
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ internet_checksum({data, size});
+ verify_ipv4_checksum({data, size});
+
+ if (size < 8) return 0;
+ Ipv4Address src{{data[0], data[1], data[2], data[3]}};
+ Ipv4Address dst{{data[4], data[5], data[6], data[7]}};
+ std::span<const unsigned char> rest{data + 8, size - 8};
+
+ verify_tcp_checksum_ipv4(src, dst, rest);
+ verify_udp_checksum_ipv4(src, dst, rest);
+ return 0;
+}