Exit and show error if unrecognized command line args are present#742
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
|
I always wondered why the code wasn't the same. Was this needed for payment requests, when they were linked to be opened by the gui application? |
|
I'm not entirely sure why they weren't the same. In the beginning, Then the argument-handling code split entirely here. Now Subsequently, the ability to call RPC methods from I can't see any good reason for "loose" arguments to remain in The "ignored options" issue was actually first raised here. The fix didn't address the specific issue exactly, as it just caught unrecognized options (ie - arguments with a hyphen). But by then, as I mentioned, the "loose" argument problem had already been fixed in |
|
I think this is needed to handle BIP 21 URIs (not to be confused with the now removed BIP 70 payment protocol). The "loose" argument is interpreted as the URI, although ignored if they could not be recognized as one. Anything that follows it is explicitly ignored to avoid argument injection, see https://achow101.com/2021/02/0.18-uri-vuln. |
250b171 to
505c726
Compare
|
Is it safer and simpler to just document that a payment URi must follow all command line options? In |
|
I could modify this PR to enforce that behavior and add the documentation to I think leaving the current Scammer: "Can you send me some testnet coins? Start your client with It's also just an annoyance. I spent an embarrassingly long time trying to figure out why |
Starting bitcoin-qt with non-dash ("-") arguments causes it to
silently ignore any later valid options. This change makes the
client exit with an error message if any such "loose" arguments
are encountered.
However, allow BIP-21 'bitcoin:' URIs only if no other options
follow.
505c726 to
51e4dc4
Compare
|
Modified to follow @hebasto 's idea of only allowing |
There was a problem hiding this comment.
tACK 51e4dc4
I like both features the error shown when invalid args are passed and the error for options that are passed following a BIP21.
For the last one and regarding the -regtest being ignored in your original PR description, I detected a similar scenario in bitcoin-cli a few months ago (bitcoin/bitcoin#26990 - still in progress) where [options] passed after a command that receives arguments are not detected by the ArgsManager, they are being interpreted as another arg of the last command.
Last thing, not part of the scope of this PR, I think we could validate the BIP21 URI grammar before opening bitcoin-qt.
| if (payment_server_token_seen && arg.startsWith("-")) { | ||
| InitError(Untranslated(strprintf("Options ('%s') cannot follow a BIP-21 payment URI", argv[i]))); | ||
| QMessageBox::critical(nullptr, PACKAGE_NAME, | ||
| // message cannot be translated because translations have not been initialized |
There was a problem hiding this comment.
Should we just initialize them in this codepath?
| } | ||
| #endif | ||
| if (payment_server_token_seen && arg.startsWith("-")) { | ||
| InitError(Untranslated(strprintf("Options ('%s') cannot follow a BIP-21 payment URI", argv[i]))); |
There was a problem hiding this comment.
| InitError(Untranslated(strprintf("Options ('%s') cannot follow a BIP-21 payment URI", argv[i]))); | |
| InitError(Untranslated(strprintf("Options (eg, '%s') cannot follow a URI", argv[i]))); |
|
lgtm ACK 51e4dc4 |
|
Fuzz CI failure can be ignored |
…for BIP21 URIs ede5014 Modify command line help to show support for BIP21 URIs (Hernan Marino) Pull request description: While reviewing a different PR (see bitcoin-core/gui#742 ) **hebasto** suggested that the help for bitcoin-qt should be updated to reflect the fact that bitcoin-qt supports an optional BIP21 URI parameter. Since this reflects actual behaviour of bitcoin-qt and is independent of whether or not the other PR gets merged, I created this simple PR to fix the help message. ACKs for top commit: kristapsk: utACK ede5014 pablomartin4btc: lgtm, re ACK ede5014 hebasto: ACK ede5014. Tree-SHA512: c456297c486bc5cc65e0e092e7ba9d51b0bd7a584d4fabca7f7ca1f8e58cbcc66e96226539c689ed0f5e7f40da220bbc4ea30b90e31e1aeeb8867a385a90209c
Fixes #741
Starting bitcoin-qt with non-hyphen ("-") arguments causes it to silently ignore any later valid options. For instance, invoking
bitcoin-qt -server=1 foo -regteston a fresh install will runmainnetinstead ofregtest.This change makes the client exit with an error message if any such "loose" arguments are encountered. This mirrors how
bitcoindhandles it:https://github.com/bitcoin/bitcoin/blob/c6287faae4c0e705a9258a340dfcf548906f12af/src/bitcoind.cpp#L127-L132
However, BIP-21
bitcoin:payment URIs are still allowed, but only if they're not followed by any additional options.