@@ -1762,28 +1762,33 @@ RPCHelpMan walletdeniabilizecoin()
17621762
17631763 std::optional<CTxDestination> shared_address;
17641764 std::set<COutPoint> inputs;
1765- unsigned int deniabilization_cycles = 0 ;
1765+ unsigned int deniabilization_cycles = UINT_MAX ;
17661766 for (const UniValue& input : request.params [0 ].get_array ().getValues ()) {
17671767 uint256 txid = ParseHashO (input, " txid" );
17681768
17691769 const UniValue& vout_v = input.find_value (" vout" );
1770- if (!vout_v.isNum ())
1770+ if (!vout_v.isNum ()) {
17711771 throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, missing vout key" );
1772+ }
17721773 int nOutput = vout_v.getInt <int >();
1773- if (nOutput < 0 )
1774+ if (nOutput < 0 ) {
17741775 throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, vout cannot be negative" );
1776+ }
17751777
17761778 COutPoint outpoint (txid, nOutput);
17771779 LOCK (pwallet->cs_wallet );
17781780 auto walletTx = pwallet->GetWalletTx (outpoint.hash );
17791781 if (!walletTx) {
1780- throw JSONRPCError (RPC_WALLET_ERROR, " Transaction not found." );
1782+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, txid not found in wallet." );
1783+ }
1784+ if (outpoint.n >= walletTx->tx ->vout .size ()) {
1785+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, vout is out of range" );
17811786 }
17821787 const auto & output = walletTx->tx ->vout [outpoint.n ];
17831788
17841789 isminetype mine = pwallet->IsMine (output);
17851790 if (mine == ISMINE_NO) {
1786- throw JSONRPCError (RPC_WALLET_ERROR , " Transaction 's output doesn't belong to this wallet." );
1791+ throw JSONRPCError (RPC_INVALID_PARAMETER , " Invalid parameter, transaction 's output doesn't belong to this wallet." );
17871792 }
17881793
17891794 bool spendable = (mine & ISMINE_SPENDABLE) != ISMINE_NO;
@@ -1794,17 +1799,21 @@ RPCHelpMan walletdeniabilizecoin()
17941799 shared_address = address;
17951800 }
17961801 else if (!(*shared_address == address)) {
1797- throw JSONRPCError (RPC_INVALID_PARAMETER, " Inputs must share the same address" );
1802+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, inputs must share the same address" );
17981803 }
17991804 } else {
1800- throw JSONRPCError (RPC_INVALID_PARAMETER, " Inputs must be spendable and have a valid address" );
1805+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, inputs must be spendable and have a valid address" );
18011806 }
18021807
18031808 inputs.emplace (outpoint);
18041809 auto cycles_res = CalculateDeniabilizationCycles (*pwallet, outpoint);
18051810 deniabilization_cycles = std::min (deniabilization_cycles, cycles_res.first );
18061811 }
18071812
1813+ if (inputs.empty ()) {
1814+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, inputs must not be empty" );
1815+ }
1816+
18081817 unsigned int confirm_target = !request.params [1 ].isNull () ? request.params [1 ].getInt <unsigned int >() : 6 ;
18091818 const bool add_to_wallet = !request.params [2 ].isNull () ? request.params [2 ].get_bool () : true ;
18101819
0 commit comments