Skip to content

Commit face251

Browse files
author
MarcoFalke
committed
bitcoin-tx: Reject + sign in vout parsing
1 parent fa8acaf commit face251

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/bitcoin-tx.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,10 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
275275

276276
// extract and validate vout
277277
const std::string& strVout = vStrInputParts[1];
278-
int64_t vout;
279-
if (!ParseInt64(strVout, &vout) || vout < 0 || vout > static_cast<int64_t>(maxVout))
278+
const auto vout{ToIntegral<uint32_t>(strVout)};
279+
if (!vout || *vout > maxVout) {
280280
throw std::runtime_error("invalid TX input vout '" + strVout + "'");
281+
}
281282

282283
// extract the optional sequence number
283284
uint32_t nSequenceIn = CTxIn::SEQUENCE_FINAL;
@@ -286,7 +287,7 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
286287
}
287288

288289
// append to transaction input list
289-
CTxIn txin(*txid, vout, CScript(), nSequenceIn);
290+
CTxIn txin{*txid, *vout, CScript{}, nSequenceIn};
290291
tx.vin.push_back(txin);
291292
}
292293

test/util/data/bitcoin-util-test.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@
264264
"error_txt": "error: invalid TX sequence id 'abcdef00'",
265265
"description": "Try to make invalid input replaceable"
266266
},
267+
{ "exec": "./bitcoin-tx",
268+
"args":
269+
["-create",
270+
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:+0"],
271+
"return_code": 1,
272+
"error_txt": "error: invalid TX input vout",
273+
"description": "Tests the check for an invalid vout value when adding an input"
274+
},
267275
{ "exec": "./bitcoin-tx",
268276
"args":
269277
["-create",

0 commit comments

Comments
 (0)