diff options
author | MarcoFalke <falke.marco@gmail.com> | 2018-09-24 14:54:10 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2018-09-24 15:09:11 -0400 |
commit | 37612099ec7314b15a07d8bac55161ed4e8e7491 (patch) | |
tree | b5c5013246a6598aad46cf244ac3a2dbd8ed1cc0 /src/wallet | |
parent | 985d28cc90eda7f637b47cda78e74099d3df8734 (diff) | |
parent | 5eb20f81d9568284dca735e4f770f41a48aa5660 (diff) |
Merge #13424: Consistently validate txid / blockhash length and encoding in rpc calls
5eb20f81d9 Consistently use ParseHashV to validate hash inputs in rpc (Ben Woosley)
Pull request description:
ParseHashV validates the length and encoding of the string and throws
an informative RPC error on failure, which is as good or better than
these alternative calls.
Note I switched ParseHashV to check string length first, because
IsHex tests that the length is even, and an error like:
"must be of length 64 (not 63, for X)" is much more informative than
"must be hexadecimal string (not X)" in that case.
Split from #13420
Tree-SHA512: f0786b41c0d7793ff76e4b2bb35547873070bbf7561d510029e8edb93f59176277efcd4d183b3185532ea69fc0bbbf3dbe9e19362e8017007ae9d51266cd78ae
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/rpcdump.cpp | 3 | ||||
-rw-r--r-- | src/wallet/rpcwallet.cpp | 20 |
2 files changed, 7 insertions, 16 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index c82d0e97d4..c97bc38e6f 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -415,8 +415,7 @@ UniValue removeprunedfunds(const JSONRPCRequest& request) LOCK2(cs_main, pwallet->cs_wallet); - uint256 hash; - hash.SetHex(request.params[0].get_str()); + uint256 hash(ParseHashV(request.params[0], "txid")); std::vector<uint256> vHash; vHash.push_back(hash); std::vector<uint256> vHashOut; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1a2dff9a96..cca50a4ee4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1638,9 +1638,8 @@ static UniValue listsinceblock(const JSONRPCRequest& request) isminefilter filter = ISMINE_SPENDABLE; if (!request.params[0].isNull() && !request.params[0].get_str().empty()) { - uint256 blockId; + uint256 blockId(ParseHashV(request.params[0], "blockhash")); - blockId.SetHex(request.params[0].get_str()); paltindex = pindex = LookupBlockIndex(blockId); if (!pindex) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); @@ -1768,8 +1767,7 @@ static UniValue gettransaction(const JSONRPCRequest& request) LOCK2(cs_main, pwallet->cs_wallet); - uint256 hash; - hash.SetHex(request.params[0].get_str()); + uint256 hash(ParseHashV(request.params[0], "txid")); isminefilter filter = ISMINE_SPENDABLE; if(!request.params[1].isNull()) @@ -1836,8 +1834,7 @@ static UniValue abandontransaction(const JSONRPCRequest& request) LOCK2(cs_main, pwallet->cs_wallet); - uint256 hash; - hash.SetHex(request.params[0].get_str()); + uint256 hash(ParseHashV(request.params[0], "txid")); if (!pwallet->mapWallet.count(hash)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); @@ -2241,17 +2238,13 @@ static UniValue lockunspent(const JSONRPCRequest& request) {"vout", UniValueType(UniValue::VNUM)}, }); - const std::string& txid = find_value(o, "txid").get_str(); - if (!IsHex(txid)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid"); - } - + const uint256 txid(ParseHashO(o, "txid")); const int nOutput = find_value(o, "vout").get_int(); if (nOutput < 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive"); } - const COutPoint outpt(uint256S(txid), nOutput); + const COutPoint outpt(txid, nOutput); const auto it = pwallet->mapWallet.find(outpt.hash); if (it == pwallet->mapWallet.end()) { @@ -3176,8 +3169,7 @@ static UniValue bumpfee(const JSONRPCRequest& request) } RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ}); - uint256 hash; - hash.SetHex(request.params[0].get_str()); + uint256 hash(ParseHashV(request.params[0], "txid")); // optional parameters CAmount totalFee = 0; |