fuzz: add network address tests

This commit is contained in:
jpk68
2026-09-02 14:55:24 -04:00
parent fdb030df51
commit 960dc81d76
15 changed files with 110 additions and 3 deletions
+3 -3
View File
@@ -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"
@@ -0,0 +1 @@
192.168.1.0/24
@@ -0,0 +1 @@
2001:db8:1234::/48
+1
View File
@@ -0,0 +1 @@
reg.i2p
+1
View File
@@ -0,0 +1 @@
xmgzqfidm3zn4y3vfljqiuyfxorifntjca3rfnwv3dbbfcrx4uca.b32.i2p
@@ -0,0 +1 @@
192.168.1.1
@@ -0,0 +1 @@
192.168.1.1:8080
@@ -0,0 +1 @@
::1
@@ -0,0 +1 @@
fe80::1ff:fe23:4567
@@ -0,0 +1 @@
nytimesn7cgmftshazwhfgzm37qxb44r64ytbb2dj3x62d2lljsciiyd.onion
@@ -0,0 +1 @@
protonirockerxow.onion
@@ -0,0 +1 @@
socks5://127.0.0.1:1080
@@ -0,0 +1 @@
socks5://username:password@[2001:db8::10]:1080
+13
View File
@@ -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
+82
View File
@@ -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 <string_view>
#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()