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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user