aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormarcofleon <marleo23@proton.me>2024-06-05 03:52:08 -0700
committermarcofleon <marleo23@proton.me>2024-06-06 13:06:23 -0700
commit193c748e44f8647a056121fc9cbb9c2efbcbfc49 (patch)
treeb4f48dd595c424c53843aebcc188151944e70a52 /src
parentff7d2054c4f1d7ff98078b9695e7c36e79a476c6 (diff)
fuzz: add I2P harness
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.test.include1
-rw-r--r--src/test/fuzz/i2p.cpp63
2 files changed, 64 insertions, 0 deletions
diff --git a/src/Makefile.test.include b/src/Makefile.test.include
index 742022ca93..4498e162c3 100644
--- a/src/Makefile.test.include
+++ b/src/Makefile.test.include
@@ -327,6 +327,7 @@ test_fuzz_fuzz_SOURCES = \
test/fuzz/headerssync.cpp \
test/fuzz/hex.cpp \
test/fuzz/http_request.cpp \
+ test/fuzz/i2p.cpp \
test/fuzz/integer.cpp \
test/fuzz/key.cpp \
test/fuzz/key_io.cpp \
diff --git a/src/test/fuzz/i2p.cpp b/src/test/fuzz/i2p.cpp
new file mode 100644
index 0000000000..3af5bed30a
--- /dev/null
+++ b/src/test/fuzz/i2p.cpp
@@ -0,0 +1,63 @@
+// Copyright (c) The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <common/args.h>
+#include <i2p.h>
+#include <netaddress.h>
+#include <netbase.h>
+#include <test/fuzz/FuzzedDataProvider.h>
+#include <test/fuzz/fuzz.h>
+#include <test/fuzz/util.h>
+#include <test/fuzz/util/net.h>
+#include <test/util/setup_common.h>
+#include <util/fs_helpers.h>
+#include <util/threadinterrupt.h>
+
+void initialize_i2p()
+{
+ static const auto testing_setup = MakeNoLogFileContext<>();
+}
+
+FUZZ_TARGET(i2p, .init = initialize_i2p)
+{
+ FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
+
+ SetMockTime(ConsumeTime(fuzzed_data_provider));
+
+ // Mock CreateSock() to create FuzzedSock.
+ auto CreateSockOrig = CreateSock;
+ CreateSock = [&fuzzed_data_provider](const sa_family_t&) {
+ return std::make_unique<FuzzedSock>(fuzzed_data_provider);
+ };
+
+ const fs::path private_key_path = gArgs.GetDataDirNet() / "fuzzed_i2p_private_key";
+ const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), 7656};
+ const Proxy sam_proxy{addr, false};
+ CThreadInterrupt interrupt;
+
+ i2p::sam::Session session{private_key_path, sam_proxy, &interrupt};
+ i2p::Connection conn;
+
+ if (session.Listen(conn)) {
+ if (session.Accept(conn)) {
+ try {
+ (void)conn.sock->RecvUntilTerminator('\n', 10ms, interrupt, i2p::sam::MAX_MSG_SIZE);
+ } catch (const std::runtime_error&) {
+ }
+ }
+ }
+
+ bool proxy_error;
+
+ if (session.Connect(CService{}, conn, proxy_error)) {
+ try {
+ conn.sock->SendComplete("verack\n", 10ms, interrupt);
+ } catch (const std::runtime_error&) {
+ }
+ }
+
+ fs::remove_all(private_key_path);
+
+ CreateSock = CreateSockOrig;
+}