diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-10-11 14:21:03 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-10-12 12:45:50 +0200 |
commit | fafab8ea5e6ed6b87fac57a5cd16a8135236cdd6 (patch) | |
tree | 5e8bb26778b4ab8222941f3fc97800aa2cba3bb7 /src/bitcoin-tx.cpp | |
parent | fa53d3d8266ad0257315d07b71b4f8a711134622 (diff) |
bitcoin-tx: Reject non-integral and out of range sequence ids
Diffstat (limited to 'src/bitcoin-tx.cpp')
-rw-r--r-- | src/bitcoin-tx.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index fc3bc6aa71..4a9818d4ec 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -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) { std::vector<std::string> vStrInputParts; @@ -261,8 +271,9 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu // extract the optional sequence number uint32_t nSequenceIn = CTxIn::SEQUENCE_FINAL; - if (vStrInputParts.size() > 2) - nSequenceIn = std::stoul(vStrInputParts[2]); + if (vStrInputParts.size() > 2) { + nSequenceIn = TrimAndParse<uint32_t>(vStrInputParts.at(2), "invalid TX sequence id"); + } // append to transaction input list CTxIn txin(txid, vout, CScript(), nSequenceIn); |