From dddd9e5fe38b81f1af6b343661b65e16b0de7c60 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 15 May 2025 20:03:25 +0200 Subject: [PATCH] bitcoin-tx: Reject + sign in nversion parsing It would be confusing to specify the sign for an unsigned value here, so reject it. --- src/bitcoin-tx.cpp | 7 +++---- test/util/data/bitcoin-util-test.json | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index e2b3a3b5545..c319c374913 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -211,12 +211,11 @@ static CAmount ExtractAndValidateValue(const std::string& strValue) static void MutateTxVersion(CMutableTransaction& tx, const std::string& cmdVal) { - uint32_t newVersion; - if (!ParseUInt32(cmdVal, &newVersion) || newVersion < 1 || newVersion > TX_MAX_STANDARD_VERSION) { + const auto ver{ToIntegral(cmdVal)}; + if (!ver || *ver < 1 || *ver > TX_MAX_STANDARD_VERSION) { throw std::runtime_error("Invalid TX version requested: '" + cmdVal + "'"); } - - tx.version = newVersion; + tx.version = *ver; } static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal) diff --git a/test/util/data/bitcoin-util-test.json b/test/util/data/bitcoin-util-test.json index 83b3c430d53..16e51124e2c 100644 --- a/test/util/data/bitcoin-util-test.json +++ b/test/util/data/bitcoin-util-test.json @@ -56,6 +56,12 @@ "output_cmp": "blanktxv2.json", "description": "Creates a blank transaction when nothing is piped into bitcoin-tx (output in json)" }, + { "exec": "./bitcoin-tx", + "args": ["-create", "nversion=+1"], + "return_code": 1, + "error_txt": "error: Invalid TX version requested", + "description": "Tests the check for invalid nversion value" + }, { "exec": "./bitcoin-tx", "args": ["-create", "nversion=1foo"], "return_code": 1,