Skip to content

Commit 57982f4

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23654: fuzz: Rework rpc fuzz target
fa52a86 fuzz: Rework rpc fuzz target (MarcoFalke) Pull request description: Changes (reason): * Return `void` in `CallRPC` (the result is unused anyway) * Reduce the `catch`-scope of `std::runtime_error` to `RPCConvertValues` (Code clarity and easier bug-finding) * Crash when an internal bug is detected (bugs are bad) ACKs for top commit: shaavan: Code Review ACK fa52a86 Tree-SHA512: 576411a0e50bca9be3e6ffaf745001b1808fd37029251f8ec2c279e0671efe91d43dd81fd4ca26871c28b119e593ee2a0043d4b75f44da578f17541ee3afd696
2 parents c9b63ab + fa52a86 commit 57982f4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/test/fuzz/rpc.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ struct RPCFuzzTestingSetup : public TestingSetup {
4141
{
4242
}
4343

44-
UniValue CallRPC(const std::string& rpc_method, const std::vector<std::string>& arguments)
44+
void CallRPC(const std::string& rpc_method, const std::vector<std::string>& arguments)
4545
{
4646
JSONRPCRequest request;
4747
request.context = &m_node;
4848
request.strMethod = rpc_method;
49-
request.params = RPCConvertValues(rpc_method, arguments);
50-
return tableRPC.execute(request);
49+
try {
50+
request.params = RPCConvertValues(rpc_method, arguments);
51+
} catch (const std::runtime_error&) {
52+
return;
53+
}
54+
tableRPC.execute(request);
5155
}
5256

5357
std::vector<std::string> GetRPCCommands() const
@@ -353,7 +357,11 @@ FUZZ_TARGET_INIT(rpc, initialize_rpc)
353357
}
354358
try {
355359
rpc_testing_setup->CallRPC(rpc_command, arguments);
356-
} catch (const UniValue&) {
357-
} catch (const std::runtime_error&) {
360+
} catch (const UniValue& json_rpc_error) {
361+
const std::string error_msg{find_value(json_rpc_error, "message").get_str()};
362+
if (error_msg.find("Internal bug detected") != std::string::npos) {
363+
// Only allow the intentional internal bug
364+
assert(error_msg.find("trigger_internal_bug") != std::string::npos);
365+
}
358366
}
359367
}

0 commit comments

Comments
 (0)