From fa77f95c2ff4ae7761208d06bcbeb59650612367 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 8 Dec 2021 14:22:48 +0100 Subject: [PATCH] fuzz: Fix RPC internal bug detection --- src/test/fuzz/rpc.cpp | 4 +++- src/util/check.h | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/fuzz/rpc.cpp b/src/test/fuzz/rpc.cpp index 44b98f7852..b6ecf1c492 100644 --- a/src/test/fuzz/rpc.cpp +++ b/src/test/fuzz/rpc.cpp @@ -360,7 +360,9 @@ FUZZ_TARGET_INIT(rpc, initialize_rpc) rpc_testing_setup->CallRPC(rpc_command, arguments); } 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) { + // 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 assert(error_msg.find("trigger_internal_bug") != std::string::npos); } diff --git a/src/util/check.h b/src/util/check.h index e60088a2c6..b12527546c 100644 --- a/src/util/check.h +++ b/src/util/check.h @@ -33,11 +33,11 @@ class NonFatalCheckError : public std::runtime_error do { \ if (!(condition)) { \ throw NonFatalCheckError( \ - strprintf("%s:%d (%s)\n" \ - "Internal bug detected: '%s'\n" \ + strprintf("Internal bug detected: '%s'\n" \ + "%s:%d (%s)\n" \ "You may report this issue here: %s\n", \ - __FILE__, __LINE__, __func__, \ (#condition), \ + __FILE__, __LINE__, __func__, \ PACKAGE_BUGREPORT)); \ } \ } while (false)