Skip to content

Commit f972b04

Browse files
committed
Merge #7825: Prevent multiple calls to ExtractDestination
0bf6f30 Prevent multiple calls to ExtractDestination (Pedro Branco)
2 parents ec45cc5 + 0bf6f30 commit f972b04

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,13 +2307,14 @@ UniValue listunspent(const UniValue& params, bool fHelp)
23072307
"\nResult\n"
23082308
"[ (array of json object)\n"
23092309
" {\n"
2310-
" \"txid\" : \"txid\", (string) the transaction id \n"
2310+
" \"txid\" : \"txid\", (string) the transaction id \n"
23112311
" \"vout\" : n, (numeric) the vout value\n"
2312-
" \"address\" : \"address\", (string) the bitcoin address\n"
2313-
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
2314-
" \"scriptPubKey\" : \"key\", (string) the script key\n"
2312+
" \"address\" : \"address\", (string) the bitcoin address\n"
2313+
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
2314+
" \"scriptPubKey\" : \"key\", (string) the script key\n"
23152315
" \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n"
23162316
" \"confirmations\" : n, (numeric) The number of confirmations\n"
2317+
" \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
23172318
" \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
23182319
" \"solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
23192320
" }\n"
@@ -2359,38 +2360,34 @@ UniValue listunspent(const UniValue& params, bool fHelp)
23592360
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
23602361
continue;
23612362

2362-
if (setAddress.size()) {
2363-
CTxDestination address;
2364-
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
2365-
continue;
2363+
CTxDestination address;
2364+
const CScript& scriptPubKey = out.tx->vout[out.i].scriptPubKey;
2365+
bool fValidAddress = ExtractDestination(scriptPubKey, address);
23662366

2367-
if (!setAddress.count(address))
2368-
continue;
2369-
}
2367+
if (setAddress.size() && (!fValidAddress || !setAddress.count(address)))
2368+
continue;
23702369

2371-
CAmount nValue = out.tx->vout[out.i].nValue;
2372-
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
23732370
UniValue entry(UniValue::VOBJ);
23742371
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
23752372
entry.push_back(Pair("vout", out.i));
2376-
CTxDestination address;
2377-
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
2373+
2374+
if (fValidAddress) {
23782375
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
2376+
23792377
if (pwalletMain->mapAddressBook.count(address))
23802378
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
2381-
}
2382-
entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end())));
2383-
if (pk.IsPayToScriptHash()) {
2384-
CTxDestination address;
2385-
if (ExtractDestination(pk, address)) {
2379+
2380+
if (scriptPubKey.IsPayToScriptHash()) {
23862381
const CScriptID& hash = boost::get<CScriptID>(address);
23872382
CScript redeemScript;
23882383
if (pwalletMain->GetCScript(hash, redeemScript))
23892384
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
23902385
}
23912386
}
2392-
entry.push_back(Pair("amount",ValueFromAmount(nValue)));
2393-
entry.push_back(Pair("confirmations",out.nDepth));
2387+
2388+
entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
2389+
entry.push_back(Pair("amount", ValueFromAmount(out.tx->vout[out.i].nValue)));
2390+
entry.push_back(Pair("confirmations", out.nDepth));
23942391
entry.push_back(Pair("spendable", out.fSpendable));
23952392
entry.push_back(Pair("solvable", out.fSolvable));
23962393
results.push_back(entry);

0 commit comments

Comments
 (0)