| 364 | } |
| 365 | |
| 366 | FUZZ_TARGET_INIT(rpc, initialize_rpc) |
| 367 | { |
| 368 | FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; |
| 369 | SetMockTime(ConsumeTime(fuzzed_data_provider)); |
| 370 | const std::string rpc_command = fuzzed_data_provider.ConsumeRandomLengthString(64); |
| 371 | if (!g_limit_to_rpc_command.empty() && rpc_command != g_limit_to_rpc_command) { |
| 372 | return; |
| 373 | } |
| 374 | const bool safe_for_fuzzing = std::find(RPC_COMMANDS_SAFE_FOR_FUZZING.begin(), RPC_COMMANDS_SAFE_FOR_FUZZING.end(), rpc_command) != RPC_COMMANDS_SAFE_FOR_FUZZING.end(); |
| 375 | if (!safe_for_fuzzing) { |
| 376 | return; |
| 377 | } |
| 378 | std::vector<std::string> arguments; |
| 379 | LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 100) { |
| 380 | arguments.push_back(ConsumeRPCArgument(fuzzed_data_provider)); |
| 381 | } |
| 382 | try { |
| 383 | rpc_testing_setup->CallRPC(rpc_command, arguments); |
| 384 | } catch (const UniValue& json_rpc_error) { |
| 385 | const std::string error_msg{find_value(json_rpc_error, "message").get_str()}; |
| 386 | // Once c++20 is allowed, starts_with can be used. |
| 387 | // if (error_msg.starts_with("Internal bug detected")) { |
| 388 | if (0 == error_msg.rfind("Internal bug detected", 0)) { |
| 389 | // Only allow the intentional internal bug |
| 390 | assert(error_msg.find("trigger_internal_bug") != std::string::npos); |
| 391 | } |
| 392 | } |
| 393 | } |
nothing calls this directly
no test coverage detected