Skip to content

Commit dddd9e5

Browse files
author
MarcoFalke
committed
bitcoin-tx: Reject + sign in nversion parsing
It would be confusing to specify the sign for an unsigned value here, so reject it.
1 parent fab06ac commit dddd9e5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/bitcoin-tx.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,11 @@ static CAmount ExtractAndValidateValue(const std::string& strValue)
211211

212212
static void MutateTxVersion(CMutableTransaction& tx, const std::string& cmdVal)
213213
{
214-
uint32_t newVersion;
215-
if (!ParseUInt32(cmdVal, &newVersion) || newVersion < 1 || newVersion > TX_MAX_STANDARD_VERSION) {
214+
const auto ver{ToIntegral<uint32_t>(cmdVal)};
215+
if (!ver || *ver < 1 || *ver > TX_MAX_STANDARD_VERSION) {
216216
throw std::runtime_error("Invalid TX version requested: '" + cmdVal + "'");
217217
}
218-
219-
tx.version = newVersion;
218+
tx.version = *ver;
220219
}
221220

222221
static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
"output_cmp": "blanktxv2.json",
5757
"description": "Creates a blank transaction when nothing is piped into bitcoin-tx (output in json)"
5858
},
59+
{ "exec": "./bitcoin-tx",
60+
"args": ["-create", "nversion=+1"],
61+
"return_code": 1,
62+
"error_txt": "error: Invalid TX version requested",
63+
"description": "Tests the check for invalid nversion value"
64+
},
5965
{ "exec": "./bitcoin-tx",
6066
"args": ["-create", "nversion=1foo"],
6167
"return_code": 1,

0 commit comments

Comments
 (0)