From 33ad384a7d69ed960f43840501b4169cda5ff8b3 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 2 Nov 2023 20:12:48 +0000 Subject: [PATCH] Fuzzers: Add a DNS packet fuzzer --- Meta/Lagom/Fuzzers/FuzzDNSPacket.cpp | 18 ++++++++++++++++++ Meta/Lagom/Fuzzers/fuzzers.cmake | 2 ++ Userland/Utilities/test-fuzz.cpp | 1 + 3 files changed, 21 insertions(+) create mode 100644 Meta/Lagom/Fuzzers/FuzzDNSPacket.cpp diff --git a/Meta/Lagom/Fuzzers/FuzzDNSPacket.cpp b/Meta/Lagom/Fuzzers/FuzzDNSPacket.cpp new file mode 100644 index 00000000000..40a4732b675 --- /dev/null +++ b/Meta/Lagom/Fuzzers/FuzzDNSPacket.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) +{ + AK::set_debug_enabled(false); + auto maybe_packet = DNS::Packet::from_raw_packet({ data, size }); + if (!maybe_packet.has_value()) + return 0; + + (void)maybe_packet.value().to_byte_buffer(); + return 0; +} diff --git a/Meta/Lagom/Fuzzers/fuzzers.cmake b/Meta/Lagom/Fuzzers/fuzzers.cmake index c4ed8102744..e7fa63826cb 100644 --- a/Meta/Lagom/Fuzzers/fuzzers.cmake +++ b/Meta/Lagom/Fuzzers/fuzzers.cmake @@ -5,6 +5,7 @@ set(FUZZER_TARGETS Brotli CyrillicDecoder DDSLoader + DNSPacket DeflateCompression DeflateDecompression ELF @@ -80,6 +81,7 @@ set(FUZZER_DEPENDENCIES_Brotli LibCompress) set(FUZZER_DEPENDENCIES_CSSParser LibWeb) set(FUZZER_DEPENDENCIES_CyrillicDecoder LibTextCodec) set(FUZZER_DEPENDENCIES_DDSLoader LibGfx) +set(FUZZER_DEPENDENCIES_DNSPacket LibDNS) set(FUZZER_DEPENDENCIES_DeflateCompression LibCompress) set(FUZZER_DEPENDENCIES_DeflateDecompression LibCompress) set(FUZZER_DEPENDENCIES_ELF LibELF) diff --git a/Userland/Utilities/test-fuzz.cpp b/Userland/Utilities/test-fuzz.cpp index 80b5036d607..6fc60c7dd69 100644 --- a/Userland/Utilities/test-fuzz.cpp +++ b/Userland/Utilities/test-fuzz.cpp @@ -19,6 +19,7 @@ T(CSSParser) \ T(CyrillicDecoder) \ T(DDSLoader) \ + T(DNSPacket) \ T(DeflateCompression) \ T(DeflateDecompression) \ T(ELF) \