From 3737d35fee283968f12e0772aa27aee4981fce41 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Fri, 21 May 2021 19:43:15 +0000 Subject: [PATCH] fuzz: Terminate immediately if a fuzzing harness ever tries to perform a DNS lookup (belts and suspenders) --- src/test/fuzz/fuzz.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp index 631c861bb6b..a33297e0ed7 100644 --- a/src/test/fuzz/fuzz.cpp +++ b/src/test/fuzz/fuzz.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -37,6 +38,14 @@ void initialize() // Terminate immediately if a fuzzing harness ever tries to create a TCP socket. CreateSock = [](const CService&) -> std::unique_ptr { std::terminate(); }; + // Terminate immediately if a fuzzing harness ever tries to perform a DNS lookup. + g_dns_lookup = [](const std::string& name, bool allow_lookup) { + if (allow_lookup) { + std::terminate(); + } + return WrappedGetAddrInfo(name, false); + }; + bool should_abort{false}; if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) { for (const auto& t : FuzzTargets()) {