mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
rpc: Fix Univalue push_backV OOM in listtransactions
This commit is contained in:
parent
f697c068eb
commit
fa8a1c0696
2 changed files with 16 additions and 6 deletions
|
@ -84,6 +84,8 @@ public:
|
|||
|
||||
bool push_back(const UniValue& val);
|
||||
bool push_backV(const std::vector<UniValue>& vec);
|
||||
template <class It>
|
||||
bool push_backV(It first, It last);
|
||||
|
||||
void __pushKV(const std::string& key, const UniValue& val);
|
||||
bool pushKV(const std::string& key, const UniValue& val);
|
||||
|
@ -137,6 +139,14 @@ public:
|
|||
friend const UniValue& find_value( const UniValue& obj, const std::string& name);
|
||||
};
|
||||
|
||||
template <class It>
|
||||
bool UniValue::push_backV(It first, It last)
|
||||
{
|
||||
if (typ != VARR) return false;
|
||||
values.insert(values.end(), first, last);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum jtokentype {
|
||||
JTOK_ERR = -1,
|
||||
JTOK_NONE = 0, // eof
|
||||
|
|
|
@ -329,11 +329,12 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
|
|||
* @param wtx The wallet transaction.
|
||||
* @param nMinDepth The minimum confirmation depth.
|
||||
* @param fLong Whether to include the JSON version of the transaction.
|
||||
* @param ret The UniValue into which the result is stored.
|
||||
* @param ret The vector into which the result is stored.
|
||||
* @param filter_ismine The "is mine" filter flags.
|
||||
* @param filter_label Optional label string to filter incoming transactions.
|
||||
*/
|
||||
static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter_ismine, const std::string* filter_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
|
||||
template <class Vec>
|
||||
static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nMinDepth, bool fLong, Vec& ret, const isminefilter& filter_ismine, const std::string* filter_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
|
||||
{
|
||||
CAmount nFee;
|
||||
std::list<COutputEntry> listReceived;
|
||||
|
@ -519,8 +520,7 @@ RPCHelpMan listtransactions()
|
|||
if (nFrom < 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
|
||||
std::vector<UniValue> ret;
|
||||
{
|
||||
LOCK(pwallet->cs_wallet);
|
||||
|
||||
|
@ -542,9 +542,9 @@ RPCHelpMan listtransactions()
|
|||
if ((nFrom + nCount) > (int)ret.size())
|
||||
nCount = ret.size() - nFrom;
|
||||
|
||||
const std::vector<UniValue>& txs = ret.getValues();
|
||||
auto txs_rev_it{std::make_move_iterator(ret.rend())};
|
||||
UniValue result{UniValue::VARR};
|
||||
result.push_backV({ txs.rend() - nFrom - nCount, txs.rend() - nFrom }); // Return oldest to newest
|
||||
result.push_backV(txs_rev_it - nFrom - nCount, txs_rev_it - nFrom); // Return oldest to newest
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue