Skip to content

Commit 926fc2a

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23707: fuzz: Fix RPC internal bug detection
fa77f95 fuzz: Fix RPC internal bug detection (MarcoFalke) Pull request description: Previously the fuzz test considered any exception which contains the string `Internal bug detected` (magic string) as a bug. This is not true when the user (fuzzer) passes in the magic string from outside. Fix that by: 1. Changing the format the string in `NonFatalCheckError` to start with the magic string. 2. Only treat exceptions that start with the magic string as internal bugs. This should fix the bug because any other exception shouldn't start with the magic string. To test: ``` echo 'bG9nZ2luZ1y+bUludGVybmFsIGJ1ZyBkZXRlY3RlZAAXCqNcjqNcjuYjeg==' | base64 --decode > /tmp/a FUZZ=rpc ./src/test/fuzz/fuzz /tmp/a ``` Before: ``` fuzz: test/fuzz/rpc.cpp:365: void rpc_fuzz_target(FuzzBufferType): Assertion `error_msg.find("trigger_internal_bug") != std::string::npos' failed. ``` After: ``` Executed /tmp/a in 0 ms ACKs for top commit: shaavan: crACK fa77f95 Tree-SHA512: 079bc97b6ce0cbad8603c7b577cc1ac0fd19e884ccbaba317588b91d98b36afeaa8cb398344b52bf12c9fd1737b3fdd8452b4e833a3b06cb3c789651955f78b8
2 parents 577bd51 + fa77f95 commit 926fc2a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/test/fuzz/rpc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ FUZZ_TARGET_INIT(rpc, initialize_rpc)
360360
rpc_testing_setup->CallRPC(rpc_command, arguments);
361361
} catch (const UniValue& json_rpc_error) {
362362
const std::string error_msg{find_value(json_rpc_error, "message").get_str()};
363-
if (error_msg.find("Internal bug detected") != std::string::npos) {
363+
// Once c++20 is allowed, starts_with can be used.
364+
// if (error_msg.starts_with("Internal bug detected")) {
365+
if (0 == error_msg.rfind("Internal bug detected", 0)) {
364366
// Only allow the intentional internal bug
365367
assert(error_msg.find("trigger_internal_bug") != std::string::npos);
366368
}

src/util/check.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class NonFatalCheckError : public std::runtime_error
3333
do { \
3434
if (!(condition)) { \
3535
throw NonFatalCheckError( \
36-
strprintf("%s:%d (%s)\n" \
37-
"Internal bug detected: '%s'\n" \
36+
strprintf("Internal bug detected: '%s'\n" \
37+
"%s:%d (%s)\n" \
3838
"You may report this issue here: %s\n", \
39-
__FILE__, __LINE__, __func__, \
4039
(#condition), \
40+
__FILE__, __LINE__, __func__, \
4141
PACKAGE_BUGREPORT)); \
4242
} \
4343
} while (false)

0 commit comments

Comments
 (0)