diff --git a/contrib/fuzz_testing/fuzz.sh b/contrib/fuzz_testing/fuzz.sh index 45904c608..e04be4784 100755 --- a/contrib/fuzz_testing/fuzz.sh +++ b/contrib/fuzz_testing/fuzz.sh @@ -10,12 +10,12 @@ fi type="$1" if test -z "$type" then - echo "usage: $0 block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|bulletproof-plus|utf8|clsag|clsag_cout|clsag_message|clsag_pubs" + echo "usage: $0 block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|bulletproof-plus|utf8|clsag|clsag_cout|clsag_message|clsag_pubs|network-address" exit 1 fi case "$type" in - block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|bulletproof-plus|utf8|clsag|clsag_cout|clsag_message|clsag_pubs) ;; - *) echo "usage: $0 block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|bulletproof-plus|utf8|clsag|clsag_cout|clsag_message|clsag_pubs"; exit 1 ;; + block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|bulletproof-plus|utf8|clsag|clsag_cout|clsag_message|clsag_pubs|network-address) ;; + *) echo "usage: $0 block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|bulletproof-plus|utf8|clsag|clsag_cout|clsag_message|clsag_pubs|network-address"; exit 1 ;; esac if test -d "fuzz-out/$type" diff --git a/tests/data/fuzz/network-address/CIDRADDR1 b/tests/data/fuzz/network-address/CIDRADDR1 new file mode 100644 index 000000000..454173677 --- /dev/null +++ b/tests/data/fuzz/network-address/CIDRADDR1 @@ -0,0 +1 @@ +192.168.1.0/24 \ No newline at end of file diff --git a/tests/data/fuzz/network-address/CIDRADDR2 b/tests/data/fuzz/network-address/CIDRADDR2 new file mode 100644 index 000000000..31bca28f1 --- /dev/null +++ b/tests/data/fuzz/network-address/CIDRADDR2 @@ -0,0 +1 @@ +2001:db8:1234::/48 \ No newline at end of file diff --git a/tests/data/fuzz/network-address/I2PADDR1 b/tests/data/fuzz/network-address/I2PADDR1 new file mode 100644 index 000000000..942242b99 --- /dev/null +++ b/tests/data/fuzz/network-address/I2PADDR1 @@ -0,0 +1 @@ +reg.i2p \ No newline at end of file diff --git a/tests/data/fuzz/network-address/I2PADDR2 b/tests/data/fuzz/network-address/I2PADDR2 new file mode 100644 index 000000000..6b810994d --- /dev/null +++ b/tests/data/fuzz/network-address/I2PADDR2 @@ -0,0 +1 @@ +xmgzqfidm3zn4y3vfljqiuyfxorifntjca3rfnwv3dbbfcrx4uca.b32.i2p \ No newline at end of file diff --git a/tests/data/fuzz/network-address/IPV4ADDR1 b/tests/data/fuzz/network-address/IPV4ADDR1 new file mode 100644 index 000000000..3fc5c1775 --- /dev/null +++ b/tests/data/fuzz/network-address/IPV4ADDR1 @@ -0,0 +1 @@ +192.168.1.1 \ No newline at end of file diff --git a/tests/data/fuzz/network-address/IPV4ADDR2 b/tests/data/fuzz/network-address/IPV4ADDR2 new file mode 100644 index 000000000..0fd6d0c21 --- /dev/null +++ b/tests/data/fuzz/network-address/IPV4ADDR2 @@ -0,0 +1 @@ +192.168.1.1:8080 \ No newline at end of file diff --git a/tests/data/fuzz/network-address/IPV6ADDR1 b/tests/data/fuzz/network-address/IPV6ADDR1 new file mode 100644 index 000000000..ce2866bdf --- /dev/null +++ b/tests/data/fuzz/network-address/IPV6ADDR1 @@ -0,0 +1 @@ +::1 \ No newline at end of file diff --git a/tests/data/fuzz/network-address/IPV6ADDR2 b/tests/data/fuzz/network-address/IPV6ADDR2 new file mode 100644 index 000000000..7220f30fe --- /dev/null +++ b/tests/data/fuzz/network-address/IPV6ADDR2 @@ -0,0 +1 @@ +fe80::1ff:fe23:4567 \ No newline at end of file diff --git a/tests/data/fuzz/network-address/ONIONADDR1 b/tests/data/fuzz/network-address/ONIONADDR1 new file mode 100644 index 000000000..20242a750 --- /dev/null +++ b/tests/data/fuzz/network-address/ONIONADDR1 @@ -0,0 +1 @@ +nytimesn7cgmftshazwhfgzm37qxb44r64ytbb2dj3x62d2lljsciiyd.onion \ No newline at end of file diff --git a/tests/data/fuzz/network-address/ONIONADDR2 b/tests/data/fuzz/network-address/ONIONADDR2 new file mode 100644 index 000000000..3df589e61 --- /dev/null +++ b/tests/data/fuzz/network-address/ONIONADDR2 @@ -0,0 +1 @@ +protonirockerxow.onion \ No newline at end of file diff --git a/tests/data/fuzz/network-address/SOCKSADDR1 b/tests/data/fuzz/network-address/SOCKSADDR1 new file mode 100644 index 000000000..ebaa0636f --- /dev/null +++ b/tests/data/fuzz/network-address/SOCKSADDR1 @@ -0,0 +1 @@ +socks5://127.0.0.1:1080 \ No newline at end of file diff --git a/tests/data/fuzz/network-address/SOCKSADDR2 b/tests/data/fuzz/network-address/SOCKSADDR2 new file mode 100644 index 000000000..b4d905ce4 --- /dev/null +++ b/tests/data/fuzz/network-address/SOCKSADDR2 @@ -0,0 +1 @@ +socks5://username:password@[2001:db8::10]:1080 \ No newline at end of file diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index 6db431e0a..fe597981d 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -223,6 +223,19 @@ set_property(TARGET parse-url_fuzz_tests PROPERTY FOLDER "tests") +monero_add_minimal_executable(network-address_fuzz_tests network_address.cpp fuzzer.cpp) +target_link_libraries(network-address_fuzz_tests + PRIVATE + net + epee + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) +set_property(TARGET network-address_fuzz_tests + PROPERTY + FOLDER "tests") + monero_add_minimal_executable(http-client_fuzz_tests http-client.cpp fuzzer.cpp) target_link_libraries(http-client_fuzz_tests PRIVATE diff --git a/tests/fuzz/network_address.cpp b/tests/fuzz/network_address.cpp new file mode 100644 index 000000000..141add8a6 --- /dev/null +++ b/tests/fuzz/network_address.cpp @@ -0,0 +1,82 @@ +// Copyright (c) 2026, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#include "include_base_utils.h" +#include "net/tor_address.h" +#include "net/i2p_address.h" +#include "net/parse.h" +#include "fuzzer.h" + +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() + +BEGIN_SIMPLE_FUZZER() + const std::string input((const char*)buf, len); + + // Onion addresses (Tor) + const auto tor = net::tor_address::make(input); + if (tor) + { + const std::string rendered = tor->str(); + net::tor_address::make(rendered); + } + + const auto onion_decoded = net::from_onion_v3(std::string_view{input}); + net::validate_v3_onion_checksum(onion_decoded); + + // I2P addresses + const auto i2p = net::i2p_address::make(input); + if (i2p) + { + const std::string rendered = i2p->str(); + net::i2p_address::make(rendered); + } + + // Generic host/port splitting, used for IPv4, IPv6, Tor, I2P, and hostnames + std::string host; + std::string port; + net::get_network_address_host_and_port(input, host, port); + + // Generic address parsing (IPv4, IPv6, Tor, I2P) + net::get_network_address(input, 18080); + + // IPv4 CIDR subnet parsing + net::get_ipv4_subnet_address(input, true); + net::get_ipv4_subnet_address(input, false); + + // TODO add IPv6 CIDR subnet parsing + + // TCP endpoint resolution (IPv4/IPv6 host/port) + net::get_tcp_endpoint(input); + + // URI parsing (scheme, userinfo, host/port) and SOCKS endpoint parsing + net::uri_components::get(input); + net::socks::endpoint::get(input); +END_SIMPLE_FUZZER()