Skip to content

Commit 06199a9

Browse files
refactor: Revert addition of univalue sighash string check
This check is already done by the rpc parser. Re-doing it is adding dead code. Instead, throwing an exception when the assumption does not hold is the already correct behavior. To make the fuzz test more accurate and not swallow all runtime errors, add a check that the passed in UniValue sighash argument is either a string or null. Co-authored-by: stickies-v <[email protected]>
1 parent 0b47c16 commit 06199a9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/rpc/util.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,16 @@ UniValue DescribeAddress(const CTxDestination& dest)
313313
return std::visit(DescribeAddressVisitor(), dest);
314314
}
315315

316+
/**
317+
* Returns a sighash value corresponding to the passed in argument.
318+
*
319+
* @pre The sighash argument should be string or null.
320+
*/
316321
int ParseSighashString(const UniValue& sighash)
317322
{
318323
if (sighash.isNull()) {
319324
return SIGHASH_DEFAULT;
320325
}
321-
if (!sighash.isStr()) {
322-
throw JSONRPCError(RPC_INVALID_PARAMETER, "sighash needs to be null or string");
323-
}
324326
const auto result{SighashFromStr(sighash.get_str())};
325327
if (!result) {
326328
throw JSONRPCError(RPC_INVALID_PARAMETER, util::ErrorString(result).original);

src/test/fuzz/parse_univalue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue)
6767
} catch (const std::runtime_error&) {
6868
}
6969
try {
70-
(void)ParseSighashString(univalue);
70+
if (univalue.isNull() || univalue.isStr()) (void)ParseSighashString(univalue);
7171
} catch (const UniValue&) {
7272
}
7373
try {

0 commit comments

Comments
 (0)