Skip to content

Commit faff25a

Browse files
author
MarcoFalke
committed
bitcoin-tx: Reject + sign in locktime
1 parent dddd9e5 commit faff25a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/bitcoin-tx.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ static void MutateTxVersion(CMutableTransaction& tx, const std::string& cmdVal)
220220

221221
static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal)
222222
{
223-
int64_t newLocktime;
224-
if (!ParseInt64(cmdVal, &newLocktime) || newLocktime < 0LL || newLocktime > 0xffffffffLL)
223+
const auto locktime{ToIntegral<uint32_t>(cmdVal)};
224+
if (!locktime) {
225225
throw std::runtime_error("Invalid TX locktime requested: '" + cmdVal + "'");
226-
227-
tx.nLockTime = (unsigned int) newLocktime;
226+
}
227+
tx.nLockTime = *locktime;
228228
}
229229

230230
static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInIdx)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@
132132
"output_cmp": "tt-locktime317000-out.json",
133133
"description": "Adds an nlocktime to a transaction (output in json)"
134134
},
135+
{ "exec": "./bitcoin-tx",
136+
"args": ["-create", "locktime=+317"],
137+
"return_code": 1,
138+
"error_txt": "error: Invalid TX locktime requested",
139+
"description": "Tests the check for invalid locktime value"
140+
},
135141
{ "exec": "./bitcoin-tx",
136142
"args": ["-create", "locktime=317000foo"],
137143
"return_code": 1,

0 commit comments

Comments
 (0)