-
Notifications
You must be signed in to change notification settings - Fork 38.8k
util: Fail to parse whitespace-only strings in ParseMoney(...) (instead of parsing as zero) #18270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9b7e757 to
e83b03a
Compare
luke-jr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK, though I prefer doing it another way
maflcko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
e83b03a to
5a507f5
Compare
|
ACK 5a507f508b90e5e12800b9218dc54d52dcd38d05 |
Same, this seems something that's better handled in the parsing code itself than as a pre-check calling out to an external function. Still, it's a good catch. Do we need to accept trailing and leading whitespace at all here? |
I don't have any strong opinions as long as it is done consistently (in order to avoid any gotchas for the callers of the function). Perhaps we can move forward with this PR as-is to get the current behaviour consistent, and then take the discussion of removal of existing logic in a follow-up issue/PR? |
5a507f5 to
43e4f12
Compare
|
ACK 43e4f1249ae2a9a1a150637c2d1d5aa8f544f46e |
43e4f12 to
5a93e67
Compare
|
@laanwj Updated. Does my implementation seem to be in line with your your suggestion? :) @MarcoFalke Could you please re-review in light of the latest update? :) |
e500e61 to
29f2e95
Compare
… parsing as zero)
29f2e95 to
100213c
Compare
5fac6b8 to
100213c
Compare
|
ACK 100213c |
theStack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 100213c
|
Ready for merge? :) |
|
ACK 100213c |
promag
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TrimString drops \f\n\r\t\v, is this intended?
| } | ||
| if (IsSpace(*p)) | ||
| break; | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, if (IsSpace(*p)) return false;
| for (; *p; p++) | ||
| if (!IsSpace(*p)) | ||
| return false; | ||
| if (*p) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to L58, replace break; with if (*p) return false;.
That is consistent with how the previously used |
…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
- 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
… parsing as zero) Summary: This is a backport of Core [[bitcoin/bitcoin#18270 | PR18270]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D8882
Fail to parse whitespace-only strings in
ParseMoney(...)(instead of parsing as0).This is a follow-up to #18225 ("util: Fail to parse empty string in
ParseMoney") which madeParseMoney("")fail instead of parsing as0.Context: #18225 (comment)
Current non-test call sites: