Skip to content

Commit 5dd28e5

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23755: rpc: Quote user supplied strings in error messages
fa24a3d rpc: Quote user supplied strings in error messages (MarcoFalke) Pull request description: I can't see a downside doing this and this fixes a fuzzing crash Background: This is a follow-up to commit 926fc2a, which introduced the "starts_with-hack". Maybe an alternative to the hack would be to assign a unique error code to internal bugs? However, I think this can be done in an separate pull request and the changes here make sense even on their own. ACKs for top commit: fanquake: ACK fa24a3d - to fix the fuzzers. Tree-SHA512: d998626406a64396a037a6d1fce22fce3dadb7567c2f9638e450ebe8fb8ae77d134e15dd02555326732208f698d77b0028bc62be9ceee9c43282b61fe95fccbd
2 parents 4279674 + fa24a3d commit 5dd28e5

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ CoinStatsHashType ParseHashType(const std::string& hash_type_input)
11341134
} else if (hash_type_input == "none") {
11351135
return CoinStatsHashType::NONE;
11361136
} else {
1137-
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s is not a valid hash_type", hash_type_input));
1137+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("'%s' is not a valid hash_type", hash_type_input));
11381138
}
11391139
}
11401140

@@ -2213,7 +2213,7 @@ static RPCHelpMan getblockstats()
22132213
for (const std::string& stat : stats) {
22142214
const UniValue& value = ret_all[stat];
22152215
if (value.isNull()) {
2216-
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid selected statistic %s", stat));
2216+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid selected statistic '%s'", stat));
22172217
}
22182218
ret.pushKV(stat, value);
22192219
}

src/rpc/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string&
210210
}
211211
CKeyID key = GetKeyForDestination(keystore, dest);
212212
if (key.IsNull()) {
213-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("%s does not refer to a key", addr_in));
213+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("'%s' does not refer to a key", addr_in));
214214
}
215215
CPubKey vchPubKey;
216216
if (!keystore.GetPubKey(key, vchPubKey)) {

test/functional/rpc_blockchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def _test_gettxoutsetinfo(self):
329329
assert 'muhash' not in r
330330

331331
# Unknown hash_type raises an error
332-
assert_raises_rpc_error(-8, "foohash is not a valid hash_type", node.gettxoutsetinfo, "foohash")
332+
assert_raises_rpc_error(-8, "'foo hash' is not a valid hash_type", node.gettxoutsetinfo, "foo hash")
333333

334334
def _test_getblockheader(self):
335335
self.log.info("Test getblockheader")

test/functional/rpc_getblockstats.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,17 @@ def run_test(self):
142142
inv_sel_stat = 'asdfghjkl'
143143
inv_stats = [
144144
[inv_sel_stat],
145-
['minfee' , inv_sel_stat],
145+
['minfee', inv_sel_stat],
146146
[inv_sel_stat, 'minfee'],
147147
['minfee', inv_sel_stat, 'maxfee'],
148148
]
149149
for inv_stat in inv_stats:
150-
assert_raises_rpc_error(-8, 'Invalid selected statistic %s' % inv_sel_stat,
150+
assert_raises_rpc_error(-8, f"Invalid selected statistic '{inv_sel_stat}'",
151151
self.nodes[0].getblockstats, hash_or_height=1, stats=inv_stat)
152152

153153
# Make sure we aren't always returning inv_sel_stat as the culprit stat
154-
assert_raises_rpc_error(-8, 'Invalid selected statistic aaa%s' % inv_sel_stat,
155-
self.nodes[0].getblockstats, hash_or_height=1, stats=['minfee' , 'aaa%s' % inv_sel_stat])
154+
assert_raises_rpc_error(-8, f"Invalid selected statistic 'aaa{inv_sel_stat}'",
155+
self.nodes[0].getblockstats, hash_or_height=1, stats=['minfee', f'aaa{inv_sel_stat}'])
156156
# Mainchain's genesis block shouldn't be found on regtest
157157
assert_raises_rpc_error(-5, 'Block not found', self.nodes[0].getblockstats,
158158
hash_or_height='000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f')

0 commit comments

Comments
 (0)