gui: Show error if unrecognized command line args are present

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.
This commit is contained in:
John Moffett 2023-06-29 12:19:18 -04:00
parent c6287faae4
commit 51e4dc49f5
2 changed files with 30 additions and 0 deletions

View File

@ -543,6 +543,34 @@ int GuiMain(int argc, char* argv[])
return EXIT_FAILURE;
}
// Error out when loose non-argument tokens are encountered on command line
// However, allow BIP-21 URIs only if no options follow
bool payment_server_token_seen = false;
for (int i = 1; i < argc; i++) {
QString arg(argv[i]);
bool invalid_token = !arg.startsWith("-");
#ifdef ENABLE_WALLET
if (arg.startsWith(BITCOIN_IPC_PREFIX, Qt::CaseInsensitive)) {
invalid_token &= false;
payment_server_token_seen = true;
}
#endif
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
QString::fromStdString("Options ('%1') cannot follow a BIP-21 payment URI").arg(QString::fromStdString(argv[i])));
return EXIT_FAILURE;
}
if (invalid_token) {
InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see bitcoin-qt -h for a list of options.", argv[i])));
QMessageBox::critical(nullptr, PACKAGE_NAME,
// message cannot be translated because translations have not been initialized
QString::fromStdString("Command line contains unexpected token '%1', see bitcoin-qt -h for a list of options.").arg(QString::fromStdString(argv[i])));
return EXIT_FAILURE;
}
}
// Now that the QApplication is setup and we have parsed our parameters, we can set the platform style
app.setupPlatformStyle();

View File

@ -54,6 +54,8 @@ class QLocalServer;
class QUrl;
QT_END_NAMESPACE
extern const QString BITCOIN_IPC_PREFIX;
class PaymentServer : public QObject
{
Q_OBJECT