fuzz: restore CreateSock in PCP targets
What changed, and why it matters
This commit fixes a small cleanup issue in Bitcoin Core's internal fuzz testing code. Fuzz tests are automated tools that feed random data into functions to find bugs; they are not part of the live Bitcoin network software. The change saves the original socket-creating function before replacing it with a fake one, then restores it afterward. This prevents one fuzz test from accidentally leaving its fake socket in place for later tests. There is no indication this affects real users, wallets, nodes, or the live Bitcoin network.
No security action required. Treat as normal code-quality/test-harness improvement.
Security signals we found
No production code changed
Change is confined to fuzz test harness
No memory safety, cryptographic, or consensus modifications
No advisory, CVE, or security disclosure referenced in commit
Evidence from the diff
In src/test/fuzz/pcp.cpp, two fuzz targets (pcp_request_port_map and natpmp_request_port_map) override the global CreateSock function with a lambda that returns a FuzzedSock. Previously they did not restore the original CreateSock after the target finished. The patch captures CreateSockOrig before the override and restores CreateSock afterward. This is a test-harness hygiene fix; it does not change production networking, consensus, or P2P behavior.
Changed components
src/test/fuzz/pcp.cppInspect captured patch +6 / −0
diff --git a/src/test/fuzz/pcp.cpp b/src/test/fuzz/pcp.cpp
index 221d237d..d843c08e 100644
--- a/src/test/fuzz/pcp.cpp
+++ b/src/test/fuzz/pcp.cpp
@@ -35,6 +35,7 @@ FUZZ_TARGET(pcp_request_port_map, .init = port_map_target_init)
FakeSteadyClock steady_clock;
// Create a mocked socket between random (and potentially invalid) client and gateway addresses.
+ auto CreateSockOrig = CreateSock;
CreateSock = [&](int domain, int type, int protocol) {
if ((domain == AF_INET || domain == AF_INET6) && type == SOCK_DGRAM && protocol == IPPROTO_UDP) {
return std::make_unique<FuzzedSock>(fuzzed_data_provider, steady_clock);
@@ -56,6 +57,8 @@ FUZZ_TARGET(pcp_request_port_map, .init = port_map_target_init)
Assert(mapping->internal.GetPort() == port);
mapping->ToString();
}
+
+ CreateSock = CreateSockOrig;
}
FUZZ_TARGET(natpmp_request_port_map, .init = port_map_target_init)
@@ -64,6 +67,7 @@ FUZZ_TARGET(natpmp_request_port_map, .init = port_map_target_init)
FakeSteadyClock steady_clock;
// Create a mocked socket between random (and potentially invalid) client and gateway addresses.
+ auto CreateSockOrig = CreateSock;
CreateSock = [&](int domain, int type, int protocol) {
if (domain == AF_INET && type == SOCK_DGRAM && protocol == IPPROTO_UDP) {
return std::make_unique<FuzzedSock>(fuzzed_data_provider, steady_clock);
@@ -84,4 +88,6 @@ FUZZ_TARGET(natpmp_request_port_map, .init = port_map_target_init)
Assert(mapping->internal.GetPort() == port);
mapping->ToString();
}
+
+ CreateSock = CreateSockOrig;
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.