Skip to content

Commit 4dc1915

Browse files
committed
check for null values in rpc args and handle appropriately
1 parent 999ef20 commit 4dc1915

File tree

6 files changed

+46
-46
lines changed

6 files changed

+46
-46
lines changed

src/rpc/blockchain.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ UniValue waitfornewblock(const JSONRPCRequest& request)
210210
+ HelpExampleRpc("waitfornewblock", "1000")
211211
);
212212
int timeout = 0;
213-
if (request.params.size() > 0)
213+
if (!request.params[0].isNull())
214214
timeout = request.params[0].get_int();
215215

216216
CUpdatedBlock block;
@@ -252,7 +252,7 @@ UniValue waitforblock(const JSONRPCRequest& request)
252252

253253
uint256 hash = uint256S(request.params[0].get_str());
254254

255-
if (request.params.size() > 1)
255+
if (!request.params[1].isNull())
256256
timeout = request.params[1].get_int();
257257

258258
CUpdatedBlock block;
@@ -295,7 +295,7 @@ UniValue waitforblockheight(const JSONRPCRequest& request)
295295

296296
int height = request.params[0].get_int();
297297

298-
if (request.params.size() > 1)
298+
if (!request.params[1].isNull())
299299
timeout = request.params[1].get_int();
300300

301301
CUpdatedBlock block;
@@ -434,7 +434,7 @@ UniValue getrawmempool(const JSONRPCRequest& request)
434434
);
435435

436436
bool fVerbose = false;
437-
if (request.params.size() > 0)
437+
if (!request.params[0].isNull())
438438
fVerbose = request.params[0].get_bool();
439439

440440
return mempoolToJSON(fVerbose);
@@ -467,7 +467,7 @@ UniValue getmempoolancestors(const JSONRPCRequest& request)
467467
}
468468

469469
bool fVerbose = false;
470-
if (request.params.size() > 1)
470+
if (!request.params[1].isNull())
471471
fVerbose = request.params[1].get_bool();
472472

473473
uint256 hash = ParseHashV(request.params[0], "parameter 1");
@@ -531,7 +531,7 @@ UniValue getmempooldescendants(const JSONRPCRequest& request)
531531
}
532532

533533
bool fVerbose = false;
534-
if (request.params.size() > 1)
534+
if (!request.params[1].isNull())
535535
fVerbose = request.params[1].get_bool();
536536

537537
uint256 hash = ParseHashV(request.params[0], "parameter 1");
@@ -666,7 +666,7 @@ UniValue getblockheader(const JSONRPCRequest& request)
666666
uint256 hash(uint256S(strHash));
667667

668668
bool fVerbose = true;
669-
if (request.params.size() > 1)
669+
if (!request.params[1].isNull())
670670
fVerbose = request.params[1].get_bool();
671671

672672
if (mapBlockIndex.count(hash) == 0)
@@ -741,7 +741,7 @@ UniValue getblock(const JSONRPCRequest& request)
741741
uint256 hash(uint256S(strHash));
742742

743743
int verbosity = 1;
744-
if (request.params.size() > 1) {
744+
if (!request.params[1].isNull()) {
745745
if(request.params[1].isNum())
746746
verbosity = request.params[1].get_int();
747747
else
@@ -984,7 +984,7 @@ UniValue gettxout(const JSONRPCRequest& request)
984984
int n = request.params[1].get_int();
985985
COutPoint out(hash, n);
986986
bool fMempool = true;
987-
if (request.params.size() > 2)
987+
if (!request.params[2].isNull())
988988
fMempool = request.params[2].get_bool();
989989

990990
Coin coin;
@@ -1037,9 +1037,9 @@ UniValue verifychain(const JSONRPCRequest& request)
10371037

10381038
LOCK(cs_main);
10391039

1040-
if (request.params.size() > 0)
1040+
if (!request.params[0].isNull())
10411041
nCheckLevel = request.params[0].get_int();
1042-
if (request.params.size() > 1)
1042+
if (!request.params[1].isNull())
10431043
nCheckDepth = request.params[1].get_int();
10441044

10451045
return CVerifyDB().VerifyDB(Params(), pcoinsTip, nCheckLevel, nCheckDepth);

src/rpc/mining.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ UniValue getnetworkhashps(const JSONRPCRequest& request)
101101
);
102102

103103
LOCK(cs_main);
104-
return GetNetworkHashPS(request.params.size() > 0 ? request.params[0].get_int() : 120, request.params.size() > 1 ? request.params[1].get_int() : -1);
104+
return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1);
105105
}
106106

107107
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
@@ -171,7 +171,7 @@ UniValue generatetoaddress(const JSONRPCRequest& request)
171171

172172
int nGenerate = request.params[0].get_int();
173173
uint64_t nMaxTries = 1000000;
174-
if (request.params.size() > 2) {
174+
if (!request.params[2].isNull()) {
175175
nMaxTries = request.params[2].get_int();
176176
}
177177

@@ -373,7 +373,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
373373
UniValue lpval = NullUniValue;
374374
std::set<std::string> setClientRules;
375375
int64_t nMaxVersionPreVB = -1;
376-
if (request.params.size() > 0)
376+
if (!request.params[0].isNull())
377377
{
378378
const UniValue& oparam = request.params[0].get_obj();
379379
const UniValue& modeval = find_value(oparam, "mode");

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ UniValue getaddednodeinfo(const JSONRPCRequest& request)
310310

311311
std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo();
312312

313-
if (request.params.size() == 1) {
313+
if (request.params.size() == 1 && !request.params[0].isNull()) {
314314
bool found = false;
315315
for (const AddedNodeInfo& info : vInfo) {
316316
if (info.strAddedNode == request.params[0].get_str()) {

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
137137

138138
// Accept either a bool (true) or a num (>=1) to indicate verbose output.
139139
bool fVerbose = false;
140-
if (request.params.size() > 1) {
140+
if (!request.params[1].isNull()) {
141141
if (request.params[1].isNum()) {
142142
if (request.params[1].get_int() != 0) {
143143
fVerbose = true;
@@ -211,7 +211,7 @@ UniValue gettxoutproof(const JSONRPCRequest& request)
211211
CBlockIndex* pblockindex = NULL;
212212

213213
uint256 hashBlock;
214-
if (request.params.size() > 1)
214+
if (!request.params[1].isNull())
215215
{
216216
hashBlock = uint256S(request.params[1].get_str());
217217
if (!mapBlockIndex.count(hashBlock))
@@ -412,7 +412,7 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
412412
}
413413
}
414414

415-
if (request.params.size() > 3 && rbfOptIn != SignalsOptInRBF(rawTx)) {
415+
if (!request.params[3].isNull() && rbfOptIn != SignalsOptInRBF(rawTx)) {
416416
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter combination: Sequence number(s) contradict replaceable option");
417417
}
418418

src/wallet/rpcdump.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ UniValue importprivkey(const JSONRPCRequest& request)
106106

107107
std::string strSecret = request.params[0].get_str();
108108
std::string strLabel = "";
109-
if (request.params.size() > 1)
109+
if (!request.params[1].isNull())
110110
strLabel = request.params[1].get_str();
111111

112112
// Whether to perform rescan after import
113113
bool fRescan = true;
114-
if (request.params.size() > 2)
114+
if (!request.params[2].isNull())
115115
fRescan = request.params[2].get_bool();
116116

117117
if (fRescan && fPruneMode)
@@ -245,20 +245,20 @@ UniValue importaddress(const JSONRPCRequest& request)
245245

246246

247247
std::string strLabel = "";
248-
if (request.params.size() > 1)
248+
if (!request.params[1].isNull())
249249
strLabel = request.params[1].get_str();
250250

251251
// Whether to perform rescan after import
252252
bool fRescan = true;
253-
if (request.params.size() > 2)
253+
if (!request.params[2].isNull())
254254
fRescan = request.params[2].get_bool();
255255

256256
if (fRescan && fPruneMode)
257257
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan is disabled in pruned mode");
258258

259259
// Whether to import a p2sh version, too
260260
bool fP2SH = false;
261-
if (request.params.size() > 3)
261+
if (!request.params[3].isNull())
262262
fP2SH = request.params[3].get_bool();
263263

264264
LOCK2(cs_main, pwallet->cs_wallet);
@@ -410,12 +410,12 @@ UniValue importpubkey(const JSONRPCRequest& request)
410410

411411

412412
std::string strLabel = "";
413-
if (request.params.size() > 1)
413+
if (!request.params[1].isNull())
414414
strLabel = request.params[1].get_str();
415415

416416
// Whether to perform rescan after import
417417
bool fRescan = true;
418-
if (request.params.size() > 2)
418+
if (!request.params[2].isNull())
419419
fRescan = request.params[2].get_bool();
420420

421421
if (fRescan && fPruneMode)
@@ -1071,7 +1071,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
10711071
//Default options
10721072
bool fRescan = true;
10731073

1074-
if (mainRequest.params.size() > 1) {
1074+
if (!mainRequest.params[1].isNull()) {
10751075
const UniValue& options = mainRequest.params[1];
10761076

10771077
if (options.exists("rescan")) {

src/wallet/rpcwallet.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ UniValue getnewaddress(const JSONRPCRequest& request)
134134

135135
// Parse the account first so we don't generate a key if there's an error
136136
std::string strAccount;
137-
if (request.params.size() > 0)
137+
if (!request.params[0].isNull())
138138
strAccount = AccountFromValue(request.params[0]);
139139

140140
if (!pwallet->IsLocked()) {
@@ -629,7 +629,7 @@ UniValue getreceivedbyaddress(const JSONRPCRequest& request)
629629

630630
// Minimum confirmations
631631
int nMinDepth = 1;
632-
if (request.params.size() > 1)
632+
if (!request.params[1].isNull())
633633
nMinDepth = request.params[1].get_int();
634634

635635
// Tally
@@ -680,7 +680,7 @@ UniValue getreceivedbyaccount(const JSONRPCRequest& request)
680680

681681
// Minimum confirmations
682682
int nMinDepth = 1;
683-
if (request.params.size() > 1)
683+
if (!request.params[1].isNull())
684684
nMinDepth = request.params[1].get_int();
685685

686686
// Get the set of pub keys assigned to account
@@ -757,10 +757,10 @@ UniValue getbalance(const JSONRPCRequest& request)
757757
const std::string* account = account_param != "*" ? &account_param : nullptr;
758758

759759
int nMinDepth = 1;
760-
if (request.params.size() > 1)
760+
if (!request.params[1].isNull())
761761
nMinDepth = request.params[1].get_int();
762762
isminefilter filter = ISMINE_SPENDABLE;
763-
if(request.params.size() > 2)
763+
if(!request.params[2].isNull())
764764
if(request.params[2].get_bool())
765765
filter = filter | ISMINE_WATCH_ONLY;
766766

@@ -963,7 +963,7 @@ UniValue sendmany(const JSONRPCRequest& request)
963963
std::string strAccount = AccountFromValue(request.params[0]);
964964
UniValue sendTo = request.params[1].get_obj();
965965
int nMinDepth = 1;
966-
if (request.params.size() > 2)
966+
if (!request.params[2].isNull())
967967
nMinDepth = request.params[2].get_int();
968968

969969
CWalletTx wtx;
@@ -1210,16 +1210,16 @@ UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bool fByA
12101210
{
12111211
// Minimum confirmations
12121212
int nMinDepth = 1;
1213-
if (params.size() > 0)
1213+
if (!params[0].isNull())
12141214
nMinDepth = params[0].get_int();
12151215

12161216
// Whether to include empty accounts
12171217
bool fIncludeEmpty = false;
1218-
if (params.size() > 1)
1218+
if (!params[1].isNull())
12191219
fIncludeEmpty = params[1].get_bool();
12201220

12211221
isminefilter filter = ISMINE_SPENDABLE;
1222-
if(params.size() > 2)
1222+
if(!params[2].isNull())
12231223
if(params[2].get_bool())
12241224
filter = filter | ISMINE_WATCH_ONLY;
12251225

@@ -1581,16 +1581,16 @@ UniValue listtransactions(const JSONRPCRequest& request)
15811581
LOCK2(cs_main, pwallet->cs_wallet);
15821582

15831583
std::string strAccount = "*";
1584-
if (request.params.size() > 0)
1584+
if (!request.params[0].isNull())
15851585
strAccount = request.params[0].get_str();
15861586
int nCount = 10;
1587-
if (request.params.size() > 1)
1587+
if (!request.params[1].isNull())
15881588
nCount = request.params[1].get_int();
15891589
int nFrom = 0;
1590-
if (request.params.size() > 2)
1590+
if (!request.params[2].isNull())
15911591
nFrom = request.params[2].get_int();
15921592
isminefilter filter = ISMINE_SPENDABLE;
1593-
if(request.params.size() > 3)
1593+
if(!request.params[3].isNull())
15941594
if(request.params[3].get_bool())
15951595
filter = filter | ISMINE_WATCH_ONLY;
15961596

@@ -1777,7 +1777,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
17771777
int target_confirms = 1;
17781778
isminefilter filter = ISMINE_SPENDABLE;
17791779

1780-
if (request.params.size() > 0)
1780+
if (!request.params[0].isNull())
17811781
{
17821782
uint256 blockId;
17831783

@@ -1796,7 +1796,7 @@ UniValue listsinceblock(const JSONRPCRequest& request)
17961796
}
17971797
}
17981798

1799-
if (request.params.size() > 1)
1799+
if (!request.params[1].isNull())
18001800
{
18011801
target_confirms = request.params[1].get_int();
18021802

@@ -1888,7 +1888,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
18881888
hash.SetHex(request.params[0].get_str());
18891889

18901890
isminefilter filter = ISMINE_SPENDABLE;
1891-
if(request.params.size() > 1)
1891+
if(!request.params[1].isNull())
18921892
if(request.params[1].get_bool())
18931893
filter = filter | ISMINE_WATCH_ONLY;
18941894

@@ -2010,7 +2010,7 @@ UniValue keypoolrefill(const JSONRPCRequest& request)
20102010

20112011
// 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
20122012
unsigned int kpSize = 0;
2013-
if (request.params.size() > 0) {
2013+
if (!request.params[0].isNull()) {
20142014
if (request.params[0].get_int() < 0)
20152015
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
20162016
kpSize = (unsigned int)request.params[0].get_int();
@@ -2603,7 +2603,7 @@ UniValue listunspent(const JSONRPCRequest& request)
26032603
CAmount nMinimumSumAmount = MAX_MONEY;
26042604
uint64_t nMaximumCount = 0;
26052605

2606-
if (request.params.size() > 4) {
2606+
if (!request.params[4].isNull()) {
26072607
const UniValue& options = request.params[4].get_obj();
26082608

26092609
if (options.exists("minimumAmount"))
@@ -2736,7 +2736,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
27362736
UniValue subtractFeeFromOutputs;
27372737
std::set<int> setSubtractFeeFromOutputs;
27382738

2739-
if (request.params.size() > 1) {
2739+
if (!request.params[1].isNull()) {
27402740
if (request.params[1].type() == UniValue::VBOOL) {
27412741
// backward compatibility bool only fallback
27422742
coinControl.fAllowWatchOnly = request.params[1].get_bool();
@@ -2904,7 +2904,7 @@ UniValue bumpfee(const JSONRPCRequest& request)
29042904
CAmount totalFee = 0;
29052905
CCoinControl coin_control;
29062906
coin_control.signalRbf = true;
2907-
if (request.params.size() > 1) {
2907+
if (!request.params[1].isNull()) {
29082908
UniValue options = request.params[1];
29092909
RPCTypeCheckObj(options,
29102910
{

0 commit comments

Comments
 (0)