mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
bitcoin-tx: Reject non-integral and out of range sequence ids
This commit is contained in:
parent
fa53d3d826
commit
fafab8ea5e
3 changed files with 37 additions and 3 deletions
|
@ -235,6 +235,16 @@ static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T TrimAndParse(const std::string& int_str, const std::string& err)
|
||||||
|
{
|
||||||
|
const auto parsed{ToIntegral<T>(TrimString(int_str))};
|
||||||
|
if (!parsed.has_value()) {
|
||||||
|
throw std::runtime_error(err + " '" + int_str + "'");
|
||||||
|
}
|
||||||
|
return parsed.value();
|
||||||
|
}
|
||||||
|
|
||||||
static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInput)
|
static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInput)
|
||||||
{
|
{
|
||||||
std::vector<std::string> vStrInputParts;
|
std::vector<std::string> vStrInputParts;
|
||||||
|
@ -261,8 +271,9 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
|
||||||
|
|
||||||
// extract the optional sequence number
|
// extract the optional sequence number
|
||||||
uint32_t nSequenceIn = CTxIn::SEQUENCE_FINAL;
|
uint32_t nSequenceIn = CTxIn::SEQUENCE_FINAL;
|
||||||
if (vStrInputParts.size() > 2)
|
if (vStrInputParts.size() > 2) {
|
||||||
nSequenceIn = std::stoul(vStrInputParts[2]);
|
nSequenceIn = TrimAndParse<uint32_t>(vStrInputParts.at(2), "invalid TX sequence id");
|
||||||
|
}
|
||||||
|
|
||||||
// append to transaction input list
|
// append to transaction input list
|
||||||
CTxIn txin(txid, vout, CScript(), nSequenceIn);
|
CTxIn txin(txid, vout, CScript(), nSequenceIn);
|
||||||
|
|
|
@ -41,7 +41,6 @@ export LC_ALL=C
|
||||||
# independent ToIntegral<T>(...) or the ParseInt*() functions.
|
# independent ToIntegral<T>(...) or the ParseInt*() functions.
|
||||||
# TODO: Reduce KNOWN_VIOLATIONS by replacing uses of locale dependent snprintf with strprintf.
|
# TODO: Reduce KNOWN_VIOLATIONS by replacing uses of locale dependent snprintf with strprintf.
|
||||||
KNOWN_VIOLATIONS=(
|
KNOWN_VIOLATIONS=(
|
||||||
"src/bitcoin-tx.cpp.*stoul"
|
|
||||||
"src/dbwrapper.cpp:.*vsnprintf"
|
"src/dbwrapper.cpp:.*vsnprintf"
|
||||||
"src/rest.cpp:.*strtol"
|
"src/rest.cpp:.*strtol"
|
||||||
"src/test/dbwrapper_tests.cpp:.*snprintf"
|
"src/test/dbwrapper_tests.cpp:.*snprintf"
|
||||||
|
|
|
@ -515,6 +515,30 @@
|
||||||
"output_cmp": "txcreatedata2.json",
|
"output_cmp": "txcreatedata2.json",
|
||||||
"description": "Creates a new transaction with one input, one address output and one data (zero value) output (output in json)"
|
"description": "Creates a new transaction with one input, one address output and one data (zero value) output (output in json)"
|
||||||
},
|
},
|
||||||
|
{ "exec": "./bitcoin-tx",
|
||||||
|
"args":
|
||||||
|
["-create",
|
||||||
|
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0:11aa"],
|
||||||
|
"return_code": 1,
|
||||||
|
"error_txt": "error: invalid TX sequence id '11aa'",
|
||||||
|
"description": "Try to parse a sequence number outside the allowed range"
|
||||||
|
},
|
||||||
|
{ "exec": "./bitcoin-tx",
|
||||||
|
"args":
|
||||||
|
["-create",
|
||||||
|
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0:-1"],
|
||||||
|
"return_code": 1,
|
||||||
|
"error_txt": "error: invalid TX sequence id '-1'",
|
||||||
|
"description": "Try to parse a sequence number outside the allowed range"
|
||||||
|
},
|
||||||
|
{ "exec": "./bitcoin-tx",
|
||||||
|
"args":
|
||||||
|
["-create",
|
||||||
|
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0:4294967296"],
|
||||||
|
"return_code": 1,
|
||||||
|
"error_txt": "error: invalid TX sequence id '4294967296'",
|
||||||
|
"description": "Try to parse a sequence number outside the allowed range"
|
||||||
|
},
|
||||||
{ "exec": "./bitcoin-tx",
|
{ "exec": "./bitcoin-tx",
|
||||||
"args":
|
"args":
|
||||||
["-create",
|
["-create",
|
||||||
|
|
Loading…
Add table
Reference in a new issue