From faff25a558ab15b5d8eeea5dd4c9c0d76350051b Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 15 May 2025 21:48:23 +0200 Subject: [PATCH] bitcoin-tx: Reject + sign in locktime --- src/bitcoin-tx.cpp | 8 ++++---- test/util/data/bitcoin-util-test.json | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index c319c374913..84bfe6995ff 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -220,11 +220,11 @@ static void MutateTxVersion(CMutableTransaction& tx, const std::string& cmdVal) static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal) { - int64_t newLocktime; - if (!ParseInt64(cmdVal, &newLocktime) || newLocktime < 0LL || newLocktime > 0xffffffffLL) + const auto locktime{ToIntegral(cmdVal)}; + if (!locktime) { throw std::runtime_error("Invalid TX locktime requested: '" + cmdVal + "'"); - - tx.nLockTime = (unsigned int) newLocktime; + } + tx.nLockTime = *locktime; } static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInIdx) diff --git a/test/util/data/bitcoin-util-test.json b/test/util/data/bitcoin-util-test.json index 16e51124e2c..d599731ca6e 100644 --- a/test/util/data/bitcoin-util-test.json +++ b/test/util/data/bitcoin-util-test.json @@ -132,6 +132,12 @@ "output_cmp": "tt-locktime317000-out.json", "description": "Adds an nlocktime to a transaction (output in json)" }, + { "exec": "./bitcoin-tx", + "args": ["-create", "locktime=+317"], + "return_code": 1, + "error_txt": "error: Invalid TX locktime requested", + "description": "Tests the check for invalid locktime value" + }, { "exec": "./bitcoin-tx", "args": ["-create", "locktime=317000foo"], "return_code": 1,