fuzz: Fix RPC internal bug detection

This commit is contained in:
MarcoFalke 2021-12-08 14:22:48 +01:00
parent 577bd51a4b
commit fa77f95c2f
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
2 changed files with 6 additions and 4 deletions

View file

@ -360,7 +360,9 @@ FUZZ_TARGET_INIT(rpc, initialize_rpc)
rpc_testing_setup->CallRPC(rpc_command, arguments); rpc_testing_setup->CallRPC(rpc_command, arguments);
} catch (const UniValue& json_rpc_error) { } catch (const UniValue& json_rpc_error) {
const std::string error_msg{find_value(json_rpc_error, "message").get_str()}; const std::string error_msg{find_value(json_rpc_error, "message").get_str()};
if (error_msg.find("Internal bug detected") != std::string::npos) { // Once c++20 is allowed, starts_with can be used.
// if (error_msg.starts_with("Internal bug detected")) {
if (0 == error_msg.rfind("Internal bug detected", 0)) {
// Only allow the intentional internal bug // Only allow the intentional internal bug
assert(error_msg.find("trigger_internal_bug") != std::string::npos); assert(error_msg.find("trigger_internal_bug") != std::string::npos);
} }

View file

@ -33,11 +33,11 @@ class NonFatalCheckError : public std::runtime_error
do { \ do { \
if (!(condition)) { \ if (!(condition)) { \
throw NonFatalCheckError( \ throw NonFatalCheckError( \
strprintf("%s:%d (%s)\n" \ strprintf("Internal bug detected: '%s'\n" \
"Internal bug detected: '%s'\n" \ "%s:%d (%s)\n" \
"You may report this issue here: %s\n", \ "You may report this issue here: %s\n", \
__FILE__, __LINE__, __func__, \
(#condition), \ (#condition), \
__FILE__, __LINE__, __func__, \
PACKAGE_BUGREPORT)); \ PACKAGE_BUGREPORT)); \
} \ } \
} while (false) } while (false)