Skip to content

Commit

Permalink
fuzz: Rework rpc fuzz target
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Dec 2, 2021
1 parent 26a1147 commit fa52a86
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/test/fuzz/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ struct RPCFuzzTestingSetup : public TestingSetup {
{
}

UniValue CallRPC(const std::string& rpc_method, const std::vector<std::string>& arguments)
void CallRPC(const std::string& rpc_method, const std::vector<std::string>& arguments)
{
JSONRPCRequest request;
request.context = &m_node;
request.strMethod = rpc_method;
request.params = RPCConvertValues(rpc_method, arguments);
return tableRPC.execute(request);
try {
request.params = RPCConvertValues(rpc_method, arguments);
} catch (const std::runtime_error&) {
return;
}
tableRPC.execute(request);
}

std::vector<std::string> GetRPCCommands() const
Expand Down Expand Up @@ -353,7 +357,11 @@ FUZZ_TARGET_INIT(rpc, initialize_rpc)
}
try {
rpc_testing_setup->CallRPC(rpc_command, arguments);
} catch (const UniValue&) {
} catch (const std::runtime_error&) {
} catch (const UniValue& json_rpc_error) {
const std::string error_msg{find_value(json_rpc_error, "message").get_str()};
if (error_msg.find("Internal bug detected") != std::string::npos) {
// Only allow the intentional internal bug
assert(error_msg.find("trigger_internal_bug") != std::string::npos);
}
}
}

0 comments on commit fa52a86

Please sign in to comment.