Page MenuHomePhabricator

Merge #13603: bitcoin-tx: Stricter check for valid integers
ClosedPublic

Authored by nakihito on Dec 6 2019, 22:47.

Details

Summary

57889e688dd0987a1e087cd48d216a413127601e bitcoin-tx: Stricter check for valid integers (Daniel Kraft)

Pull request description:

Just calling `atoi` to convert strings to integers does not check for valid integers very thoroughly; in particular, it just ignores everything starting from the first non-numeral character.  Even a string like "foo" is fine and silently returns 0.

This meant that `bitcoin-tx` would not fail if such a string was passed in various places where an integer is expected (like the `locktime` or an input/output index); this means that it would, for instance, silently accept a typo and interpret it in an unexpected way.

In this change, we use `ParseInt64` for parsing strings to integers, which actually verifies that the full string is valid as number.  New tests in the `bitcoin-util-test` cover the new error paths.

This fixes #13599.

Tree-SHA512: 146a0af275e9f57784e5d0582d3defbac35551b54b6b7232f8a0b20db04aa611125e52aa4512ef2f8ed2cafc2a12fe586f9d10ed66d641cff090288f279b1988

Backport of Core PR13603
https://github.com/bitcoin/bitcoin/pull/13603/

Review note: one test case is excluded (see https://github.com/bitcoin/bitcoin/pull/13603/files#diff-56081e3ccaa6b59f0fbd1c2e34b95a49R105) because we do not support the replaceable option for bitcoin-tx.

Test Plan
make check

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Owners added a reviewer: Restricted Owners Package.Dec 6 2019, 22:47
nakihito requested review of this revision.Dec 6 2019, 22:55
nakihito added inline comments.
src/bitcoin-tx.cpp
1 ↗(On Diff #14682)
src/bitcoin-tx.cpp
1 ↗(On Diff #14682)

If you're going to touch this, why not the current year?

This revision is now accepted and ready to land.Dec 9 2019, 00:28