Skip to content

Commit 62fcf27

Browse files
committed
Merge #8171: [RPC] Fix createrawtx sequence number unsigned int parsing
6fa950a [RPC] Fix createrawtx sequence number unsigned int parsing (Jonas Schnelli)
2 parents e4bb4a8 + 6fa950a commit 62fcf27

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

qa/rpc-tests/rawtransactions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ def run_test(self):
143143
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
144144
decrawtx= self.nodes[0].decoderawtransaction(rawtx)
145145
assert_equal(decrawtx['vin'][0]['sequence'], 1000)
146+
147+
inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1, 'sequence' : -1}]
148+
outputs = { self.nodes[0].getnewaddress() : 1 }
149+
assert_raises(JSONRPCException, self.nodes[0].createrawtransaction, inputs, outputs)
150+
151+
inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1, 'sequence' : 4294967296}]
152+
outputs = { self.nodes[0].getnewaddress() : 1 }
153+
assert_raises(JSONRPCException, self.nodes[0].createrawtransaction, inputs, outputs)
154+
155+
inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1, 'sequence' : 4294967294}]
156+
outputs = { self.nodes[0].getnewaddress() : 1 }
157+
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
158+
decrawtx= self.nodes[0].decoderawtransaction(rawtx)
159+
assert_equal(decrawtx['vin'][0]['sequence'], 4294967294)
146160

147161
if __name__ == '__main__':
148162
RawTransactionsTest().main()

src/rpc/rawtransaction.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,13 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
388388

389389
// set the sequence number if passed in the parameters object
390390
const UniValue& sequenceObj = find_value(o, "sequence");
391-
if (sequenceObj.isNum())
392-
nSequence = sequenceObj.get_int();
391+
if (sequenceObj.isNum()) {
392+
int64_t seqNr64 = sequenceObj.get_int64();
393+
if (seqNr64 < 0 || seqNr64 > std::numeric_limits<uint32_t>::max())
394+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range");
395+
else
396+
nSequence = (uint32_t)seqNr64;
397+
}
393398

394399
CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);
395400

0 commit comments

Comments
 (0)