bitcoin-tx accepts non-numeral input/output indices #13599

issue domob1812 opened this issue on July 5, 2018
  1. domob1812 commented at 2:36 PM on July 5, 2018: contributor

    Some commands of bitcoin-tx accept an index of an existing input/output, e.g. delin or delout. And while the index is checked for being out-of-bounds, garbage (non-numeral characters) are happily accepted. All of the following are fine:

    $ bitcoin-tx -create outaddr=1:1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd delout=
    $ bitcoin-tx -create outaddr=1:1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd delout=foobar
    $ bitcoin-tx -create outaddr=1:1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd delout=0bla

    I think all of them should throw an error instead of silently treating the index as zero.

    The reason for this is that internally, atoi is called - and that by design discards anything after the first non-numeric character (and may just return zero if there are no numerals at all).

    A possible fix would be to use strtol instead and to verify that the returned endptr is actually the end of the input string. Alternatively, one could convert the integer back to a string and require that it matches the input string exactly.

  2. domob1812 commented at 2:36 PM on July 5, 2018: contributor

    I'm happy to work on a PR (will be simple enough) if others agree this should be fixed.

  3. sipa commented at 5:02 PM on July 5, 2018: member

    Yes, let's fix this.

  4. laanwj closed this on Jul 9, 2018

  5. laanwj referenced this in commit 453ae5ec9f on Jul 9, 2018
  6. PastaPastaPasta referenced this in commit 7776fd8937 on Dec 16, 2020
  7. PastaPastaPasta referenced this in commit 77b67d10e7 on Dec 18, 2020
  8. PastaPastaPasta referenced this in commit 44c7301288 on Dec 18, 2020
  9. MarcoFalke locked this on Sep 8, 2021
  10. gades referenced this in commit e7bd1601ef on May 4, 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 18:15 UTC

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