Merge #7825: Prevent multiple calls to ExtractDestination

0bf6f30 Prevent multiple calls to ExtractDestination (Pedro Branco)
This commit is contained in:
Pieter Wuille 2016-06-03 00:06:50 +02:00
commit f972b04d63
No known key found for this signature in database
GPG key ID: DBA1A67379A1A931

View file

@ -2307,13 +2307,14 @@ UniValue listunspent(const UniValue& params, bool fHelp)
"\nResult\n" "\nResult\n"
"[ (array of json object)\n" "[ (array of json object)\n"
" {\n" " {\n"
" \"txid\" : \"txid\", (string) the transaction id \n" " \"txid\" : \"txid\", (string) the transaction id \n"
" \"vout\" : n, (numeric) the vout value\n" " \"vout\" : n, (numeric) the vout value\n"
" \"address\" : \"address\", (string) the bitcoin address\n" " \"address\" : \"address\", (string) the bitcoin address\n"
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n" " \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
" \"scriptPubKey\" : \"key\", (string) the script key\n" " \"scriptPubKey\" : \"key\", (string) the script key\n"
" \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n" " \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n"
" \"confirmations\" : n, (numeric) The number of confirmations\n" " \"confirmations\" : n, (numeric) The number of confirmations\n"
" \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
" \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n" " \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
" \"solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n" " \"solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
" }\n" " }\n"
@ -2359,38 +2360,34 @@ UniValue listunspent(const UniValue& params, bool fHelp)
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth) if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
continue; continue;
if (setAddress.size()) { CTxDestination address;
CTxDestination address; const CScript& scriptPubKey = out.tx->vout[out.i].scriptPubKey;
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) bool fValidAddress = ExtractDestination(scriptPubKey, address);
continue;
if (!setAddress.count(address)) if (setAddress.size() && (!fValidAddress || !setAddress.count(address)))
continue; continue;
}
CAmount nValue = out.tx->vout[out.i].nValue;
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
UniValue entry(UniValue::VOBJ); UniValue entry(UniValue::VOBJ);
entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
entry.push_back(Pair("vout", out.i)); entry.push_back(Pair("vout", out.i));
CTxDestination address;
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { if (fValidAddress) {
entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
if (pwalletMain->mapAddressBook.count(address)) if (pwalletMain->mapAddressBook.count(address))
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
}
entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end()))); if (scriptPubKey.IsPayToScriptHash()) {
if (pk.IsPayToScriptHash()) {
CTxDestination address;
if (ExtractDestination(pk, address)) {
const CScriptID& hash = boost::get<CScriptID>(address); const CScriptID& hash = boost::get<CScriptID>(address);
CScript redeemScript; CScript redeemScript;
if (pwalletMain->GetCScript(hash, redeemScript)) if (pwalletMain->GetCScript(hash, redeemScript))
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
} }
} }
entry.push_back(Pair("amount",ValueFromAmount(nValue)));
entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
entry.push_back(Pair("amount", ValueFromAmount(out.tx->vout[out.i].nValue)));
entry.push_back(Pair("confirmations", out.nDepth));
entry.push_back(Pair("spendable", out.fSpendable)); entry.push_back(Pair("spendable", out.fSpendable));
entry.push_back(Pair("solvable", out.fSolvable)); entry.push_back(Pair("solvable", out.fSolvable));
results.push_back(entry); results.push_back(entry);