Skip to content

Commit fa8acaf

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

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/bitcoin-tx.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,15 @@ static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal)
229229

230230
static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInIdx)
231231
{
232-
// parse requested index
233-
int64_t inIdx = -1;
234-
if (strInIdx != "" && (!ParseInt64(strInIdx, &inIdx) || inIdx < 0 || inIdx >= static_cast<int64_t>(tx.vin.size()))) {
232+
const auto idx{ToIntegral<uint32_t>(strInIdx)};
233+
if (strInIdx != "" && (!idx || *idx >= tx.vin.size())) {
235234
throw std::runtime_error("Invalid TX input index '" + strInIdx + "'");
236235
}
237236

238237
// set the nSequence to MAX_INT - 2 (= RBF opt in flag)
239-
int cnt = 0;
238+
uint32_t cnt{0};
240239
for (CTxIn& txin : tx.vin) {
241-
if (strInIdx == "" || cnt == inIdx) {
240+
if (strInIdx == "" || cnt == *idx) {
242241
if (txin.nSequence > MAX_BIP125_RBF_SEQUENCE) {
243242
txin.nSequence = MAX_BIP125_RBF_SEQUENCE;
244243
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@
177177
"error_txt": "error: Invalid TX input index",
178178
"description": "Tests the check for an invalid string input index with replaceable"
179179
},
180+
{ "exec": "./bitcoin-tx",
181+
"args":
182+
["-create",
183+
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
184+
"replaceable=+0"],
185+
"return_code": 1,
186+
"error_txt": "error: Invalid TX input index",
187+
"description": "Tests the check for an invalid string input index with replaceable"
188+
},
180189
{
181190
"exec": "./bitcoin-tx",
182191
"args":

0 commit comments

Comments
 (0)