bitcoin-tx: Reject non-integral and out of range int strings #23253

pull MarcoFalke wants to merge 3 commits into bitcoin:master from MarcoFalke:2110-utilTxSeqId changing 3 files +61 −7
  1. MarcoFalke commented at 12:03 PM on October 11, 2021: member

    Seems odd to silently accept arbitrary strings that don't even represent integral values.

    Fix that.

  2. MarcoFalke renamed this:
    bitcoin-tx: Reject non-integral and out of range sequence ids
    bitcoin-tx: Reject non-integral and out of range int strings
    on Oct 11, 2021
  3. MarcoFalke force-pushed on Oct 11, 2021
  4. DrahtBot added the label Utils/log/libs on Oct 11, 2021
  5. practicalswift commented at 1:33 PM on October 11, 2021: contributor

    Concept ACK

  6. promag commented at 8:32 AM on October 12, 2021: member

    Code review ACK fa334a8765a88f18e7a63d908b672b27343d8219.

    My only suggestion is to create a helper to avoid duplicate code, like:

    template <typename T>
    T ParseIntegral(const std::string& str, const std::string& error_msg)
    {
        const auto parsed{ToIntegral<T>(TrimString(str))};
        if (!parsed.has_value()) {
            throw std::runtime_error(error_msg + " '" + str + "'");
        }
        return parsed.value();
    }
    
  7. test: Check that bitcoin-tx accepts whitespace around sequence id and multisig numbers fa53d3d826
  8. bitcoin-tx: Reject non-integral and out of range sequence ids fafab8ea5e
  9. bitcoin-tx: Reject non-integral and out of range multisig numbers fa6f29de51
  10. MarcoFalke force-pushed on Oct 12, 2021
  11. MarcoFalke commented at 10:47 AM on October 12, 2021: member

    Thanks, done

  12. promag commented at 11:16 AM on October 12, 2021: member

    Code review ACK fa6f29de516c7af5206b91b59ada466032329250.

  13. practicalswift commented at 8:14 AM on October 13, 2021: contributor

    cr ACK fa6f29de516c7af5206b91b59ada466032329250

  14. in src/bitcoin-tx.cpp:243 in fa6f29de51
     234 | @@ -235,6 +235,16 @@ static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInId
     235 |      }
     236 |  }
     237 |  
     238 | +template <typename T>
     239 | +static T TrimAndParse(const std::string& int_str, const std::string& err)
     240 | +{
     241 | +    const auto parsed{ToIntegral<T>(TrimString(int_str))};
     242 | +    if (!parsed.has_value()) {
     243 | +        throw std::runtime_error(err + " '" + int_str + "'");
    


    laanwj commented at 11:36 AM on October 13, 2021:

    It is very un-us to throw an exception for a parse error here. But as this is local to bitcoin-tx where this is explicitly caught I think it's acceptable.

  15. laanwj commented at 11:37 AM on October 13, 2021: member

    Code review ACK fa6f29de516c7af5206b91b59ada466032329250

  16. laanwj merged this on Oct 13, 2021
  17. laanwj closed this on Oct 13, 2021

  18. sidhujag referenced this in commit e72db9bd46 on Oct 13, 2021
  19. MarcoFalke deleted the branch on Oct 22, 2021
  20. DrahtBot locked this on Oct 30, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me