diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-12-08 16:50:21 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-12-08 16:50:28 +0100 |
commit | 926fc2a0d4ff64cf2ff8e1dfa64eca2ebd24e090 (patch) | |
tree | 3246ff56ec34c154cb49f5aaea19d3f7710b7158 | |
parent | 577bd51a4b8de066466a445192c1c653872657e2 (diff) | |
parent | fa77f95c2ff4ae7761208d06bcbeb59650612367 (diff) |
Merge bitcoin/bitcoin#23707: fuzz: Fix RPC internal bug detection
fa77f95c2ff4ae7761208d06bcbeb59650612367 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 fa77f95c2ff4ae7761208d06bcbeb59650612367
Tree-SHA512: 079bc97b6ce0cbad8603c7b577cc1ac0fd19e884ccbaba317588b91d98b36afeaa8cb398344b52bf12c9fd1737b3fdd8452b4e833a3b06cb3c789651955f78b8
-rw-r--r-- | src/test/fuzz/rpc.cpp | 4 | ||||
-rw-r--r-- | 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) |