Skip to content

Commit 51e4dc4

Browse files
committed
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.
1 parent c6287fa commit 51e4dc4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/qt/bitcoin.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,34 @@ int GuiMain(int argc, char* argv[])
543543
return EXIT_FAILURE;
544544
}
545545

546+
// Error out when loose non-argument tokens are encountered on command line
547+
// However, allow BIP-21 URIs only if no options follow
548+
bool payment_server_token_seen = false;
549+
for (int i = 1; i < argc; i++) {
550+
QString arg(argv[i]);
551+
bool invalid_token = !arg.startsWith("-");
552+
#ifdef ENABLE_WALLET
553+
if (arg.startsWith(BITCOIN_IPC_PREFIX, Qt::CaseInsensitive)) {
554+
invalid_token &= false;
555+
payment_server_token_seen = true;
556+
}
557+
#endif
558+
if (payment_server_token_seen && arg.startsWith("-")) {
559+
InitError(Untranslated(strprintf("Options ('%s') cannot follow a BIP-21 payment URI", argv[i])));
560+
QMessageBox::critical(nullptr, PACKAGE_NAME,
561+
// message cannot be translated because translations have not been initialized
562+
QString::fromStdString("Options ('%1') cannot follow a BIP-21 payment URI").arg(QString::fromStdString(argv[i])));
563+
return EXIT_FAILURE;
564+
}
565+
if (invalid_token) {
566+
InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see bitcoin-qt -h for a list of options.", argv[i])));
567+
QMessageBox::critical(nullptr, PACKAGE_NAME,
568+
// message cannot be translated because translations have not been initialized
569+
QString::fromStdString("Command line contains unexpected token '%1', see bitcoin-qt -h for a list of options.").arg(QString::fromStdString(argv[i])));
570+
return EXIT_FAILURE;
571+
}
572+
}
573+
546574
// Now that the QApplication is setup and we have parsed our parameters, we can set the platform style
547575
app.setupPlatformStyle();
548576

src/qt/paymentserver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class QLocalServer;
5454
class QUrl;
5555
QT_END_NAMESPACE
5656

57+
extern const QString BITCOIN_IPC_PREFIX;
58+
5759
class PaymentServer : public QObject
5860
{
5961
Q_OBJECT

0 commit comments

Comments
 (0)