diff --git a/doc/release-notes-28113.md b/doc/release-notes-28113.md index c1a3a07b175..c9f418dbbbd 100644 --- a/doc/release-notes-28113.md +++ b/doc/release-notes-28113.md @@ -2,6 +2,6 @@ RPC Wallet ---------- - The `signrawtransactionwithkey`, `signrawtransactionwithwallet`, - `walletprocesspsbt` and `descriptorprocesspsbt` calls now return more - specific RPC_INVALID_PARAMETER instead of RPC_PARSE_ERROR if their - sighashtype argument is malformed or not a string. + `walletprocesspsbt` and `descriptorprocesspsbt` calls now return the more + specific RPC_INVALID_PARAMETER error instead of RPC_MISC_ERROR if their + sighashtype argument is malformed. 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 {