Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Feb 28, 2020

Supplying a fee rate or an amount on the command line as an empty string, which currently parses as 0 seems fragile and confusing. See for example the confusion in #18214.

Fixes #18214

@instagibbs
Copy link
Member

was just about to suggest that... looking

@instagibbs
Copy link
Member

utACK 8888461

@Empact
Copy link
Contributor

Empact commented Feb 28, 2020

Code Review ACK 8888461

@maflcko maflcko removed the Tests label Feb 28, 2020
@achow101
Copy link
Member

ACK 8888461

@fanquake fanquake merged commit 9027960 into bitcoin:master Feb 29, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 29, 2020
8888461 util: Fail to parse empty string in ParseMoney (MarcoFalke)
fab30b6 util: Remove unused ParseMoney that takes a c_str (MarcoFalke)

Pull request description:

  Supplying a fee rate or an amount on the command line as an empty string, which currently parses as `0` seems fragile and confusing. See for example the confusion in bitcoin#18214.

  Fixes bitcoin#18214

ACKs for top commit:
  Empact:
    Code Review ACK bitcoin@8888461
  achow101:
    ACK 8888461
  instagibbs:
    utACK bitcoin@8888461

Tree-SHA512: ac2d6b7fa89fe5809c34d5f49831042032591c34fb3c76908d72fed51e8bced41bf2b41dc1b3be34ee691a40463355649857a7a8f378709d38ae89503feb11c2
@maflcko maflcko deleted the 2002-utilMoney branch February 29, 2020 17:31
@practicalswift
Copy link
Contributor

Since leading spaces are stripped by ParseMoney(…) shouldn't " " (one space), two spaces, three spaces, etc. fail in the same way as "" (empty string)?

In other words if (TrimString(s, " ").empty()) { return false; } instead of if (s.empty()) { return false; }?

@luke-jr
Copy link
Member

luke-jr commented Mar 4, 2020

Agree with @practicalswift - this wasn't complete enough.

@maflcko
Copy link
Member Author

maflcko commented Mar 4, 2020

Is it possible to pass in a string that consists only of spaces on the command line?

@instagibbs
Copy link
Member

bitcoind -regtest "-fallbackfee= "

harder to hit obviously but possible

@practicalswift
Copy link
Contributor

practicalswift commented Mar 4, 2020

@MarcoFalke It sure is but I'm not convinced that is even relevant: ParseMoney(…) doesn't come with any documented precondition that input must come from the command line :)

We should strive to write robust functions that gracefully and consistently handle all kinds of crazy and potentially malicious input, not functions that happen to work with the "happy path input" we currently feed them with. Robust is strictly better than fragile and future-proof is strictly better than at-the-moment-proof :)

If the intention here was to only fix the command-line handling of -fallbackfee= then the emptiness check should not have been added to ParseMoney(…) but to the code at the call site, no? :)

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Mar 5, 2020
maflcko pushed a commit that referenced this pull request Mar 27, 2020
…ey(...) (instead of parsing as zero)

100213c util: Fail to parse space-only strings in ParseMoney(...) (instead of parsing as zero) (practicalswift)

Pull request description:

  Fail to parse whitespace-only strings in `ParseMoney(...)` (instead of parsing as `0`).

  This is a follow-up to #18225 ("util: Fail to parse empty string in `ParseMoney`") which made `ParseMoney("")` fail instead of parsing as `0`.

  Context: #18225 (comment)

  Current non-test call sites:

  ```
  $ git grep ParseMoney ":(exclude)src/test/"
  src/bitcoin-tx.cpp:    if (!ParseMoney(strValue, value))
  src/init.cpp:        if (!ParseMoney(gArgs.GetArg("-incrementalrelayfee", ""), n))
  src/init.cpp:        if (!ParseMoney(gArgs.GetArg("-minrelaytxfee", ""), n)) {
  src/init.cpp:        if (!ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n))
  src/init.cpp:        if (!ParseMoney(gArgs.GetArg("-dustrelayfee", ""), n))
  src/miner.cpp:    if (gArgs.IsArgSet("-blockmintxfee") && ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) {
  src/util/moneystr.cpp:bool ParseMoney(const std::string& str, CAmount& nRet)
  src/util/moneystr.h:NODISCARD bool ParseMoney(const std::string& str, CAmount& nRet);
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-mintxfee", ""), n) || 0 == n) {
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-fallbackfee", ""), nFeePerK)) {
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-discardfee", ""), nFeePerK)) {
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nFeePerK)) {
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee)) {
  ```

ACKs for top commit:
  Empact:
    ACK 100213c
  sipa:
    ACK 100213c
  theStack:
    ACK 100213c

Tree-SHA512: cadfb1ac8276cf54736c3444705f2650e7a08023673aedc729fabe751ae80f6c490fc0945ee38dbfd02c95e4d9853d1e4c84f5d3c310f44eaf3585afec8a4c22
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 28, 2020
…arseMoney(...) (instead of parsing as zero)

100213c util: Fail to parse space-only strings in ParseMoney(...) (instead of parsing as zero) (practicalswift)

Pull request description:

  Fail to parse whitespace-only strings in `ParseMoney(...)` (instead of parsing as `0`).

  This is a follow-up to bitcoin#18225 ("util: Fail to parse empty string in `ParseMoney`") which made `ParseMoney("")` fail instead of parsing as `0`.

  Context: bitcoin#18225 (comment)

  Current non-test call sites:

  ```
  $ git grep ParseMoney ":(exclude)src/test/"
  src/bitcoin-tx.cpp:    if (!ParseMoney(strValue, value))
  src/init.cpp:        if (!ParseMoney(gArgs.GetArg("-incrementalrelayfee", ""), n))
  src/init.cpp:        if (!ParseMoney(gArgs.GetArg("-minrelaytxfee", ""), n)) {
  src/init.cpp:        if (!ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n))
  src/init.cpp:        if (!ParseMoney(gArgs.GetArg("-dustrelayfee", ""), n))
  src/miner.cpp:    if (gArgs.IsArgSet("-blockmintxfee") && ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) {
  src/util/moneystr.cpp:bool ParseMoney(const std::string& str, CAmount& nRet)
  src/util/moneystr.h:NODISCARD bool ParseMoney(const std::string& str, CAmount& nRet);
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-mintxfee", ""), n) || 0 == n) {
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-fallbackfee", ""), nFeePerK)) {
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-discardfee", ""), nFeePerK)) {
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nFeePerK)) {
  src/wallet/wallet.cpp:        if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee)) {
  ```

ACKs for top commit:
  Empact:
    ACK bitcoin@100213c
  sipa:
    ACK 100213c
  theStack:
    ACK bitcoin@100213c

Tree-SHA512: cadfb1ac8276cf54736c3444705f2650e7a08023673aedc729fabe751ae80f6c490fc0945ee38dbfd02c95e4d9853d1e4c84f5d3c310f44eaf3585afec8a4c22
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Apr 9, 2020
- rpc/wallet: initialize nFeeRequired to avoid using garbage value on failure bitcoin#18274
- httpserver: use own HTTP status codes bitcoin#18168
- tests: Add fuzzing harnesses for various Base{32,58,64} and hex related functions bitcoin#17229
- util: Don't allow Base32/64-decoding or ParseMoney(…) on strings with embedded NUL characters. Add tests. bitcoin#17753
- util: Fail to parse empty string in ParseMoney bitcoin#18225
- util: Fail to parse whitespace-only strings in ParseMoney(...) (instead of parsing as zero) bitcoin#18270
- Replace the LogPrint function with a macro bitcoin#17218
- Fix wallet unload race condition bitcoin#18338
- qt: Fix Window -> Minimize menu item bitcoin#18549
- windows: Enable heap terminate-on-corruption bitcoin#17916
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
8888461 util: Fail to parse empty string in ParseMoney (MarcoFalke)
fab30b6 util: Remove unused ParseMoney that takes a c_str (MarcoFalke)

Pull request description:

  Supplying a fee rate or an amount on the command line as an empty string, which currently parses as `0` seems fragile and confusing. See for example the confusion in bitcoin#18214.

  Fixes bitcoin#18214

ACKs for top commit:
  Empact:
    Code Review ACK bitcoin@8888461
  achow101:
    ACK 8888461
  instagibbs:
    utACK bitcoin@8888461

Tree-SHA512: ac2d6b7fa89fe5809c34d5f49831042032591c34fb3c76908d72fed51e8bced41bf2b41dc1b3be34ee691a40463355649857a7a8f378709d38ae89503feb11c2
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 4, 2021
Summary:
Remove unused ParseMoney that takes a c_str, fail to parse empty string

> Supplying a fee rate or an amount on the command line as an empty string, which currently parses as 0 seems fragile and confusing.

This is a backport of Core [[bitcoin/bitcoin#18225 | PR18225]]

Test Plan: `ninja && ninja check`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D8775
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants