From 06199a995f20c55583f6948cfe99e608679fcdf1 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 26 Jul 2023 11:39:54 +0200 Subject: [PATCH] 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 --- src/rpc/util.cpp | 8 +++++--- src/test/fuzz/parse_univalue.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 377181dd815..faae840d40f 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -313,14 +313,16 @@ UniValue DescribeAddress(const CTxDestination& dest) return std::visit(DescribeAddressVisitor(), dest); } +/** + * Returns a sighash value corresponding to the passed in argument. + * + * @pre The sighash argument should be string or null. +*/ int ParseSighashString(const UniValue& sighash) { if (sighash.isNull()) { return SIGHASH_DEFAULT; } - if (!sighash.isStr()) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "sighash needs to be null or string"); - } const auto result{SighashFromStr(sighash.get_str())}; if (!result) { throw JSONRPCError(RPC_INVALID_PARAMETER, util::ErrorString(result).original); diff --git a/src/test/fuzz/parse_univalue.cpp b/src/test/fuzz/parse_univalue.cpp index c9096d0386d..a3d6ab63752 100644 --- a/src/test/fuzz/parse_univalue.cpp +++ b/src/test/fuzz/parse_univalue.cpp @@ -67,7 +67,7 @@ FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue) } catch (const std::runtime_error&) { } try { - (void)ParseSighashString(univalue); + if (univalue.isNull() || univalue.isStr()) (void)ParseSighashString(univalue); } catch (const UniValue&) { } try {