Give QApplication dummy arguments

Discards any Qt built-in command line arguments and replaces them
with dummy argv that only contains the binary name. Solves CVE-2021-3401.

Manually ported from bitcoin/bitcoin@a2714a5c
This commit is contained in:
Patrick Lodder 2021-11-03 09:53:04 -04:00
parent 49e947f282
commit d2b1a61753
No known key found for this signature in database
GPG key ID: 7C523F5FBABE80E7
2 changed files with 11 additions and 5 deletions

View file

@ -197,7 +197,7 @@ class BitcoinApplication: public QApplication
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BitcoinApplication(int &argc, char **argv); explicit BitcoinApplication();
~BitcoinApplication(); ~BitcoinApplication();
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
@ -312,8 +312,11 @@ void BitcoinCore::shutdown()
} }
} }
BitcoinApplication::BitcoinApplication(int &argc, char **argv): static int qt_argc = 1;
QApplication(argc, argv), static const char* qt_argv = "dogecoin-qt";
BitcoinApplication::BitcoinApplication():
QApplication(qt_argc, const_cast<char **>(&qt_argv)),
coreThread(0), coreThread(0),
optionsModel(0), optionsModel(0),
clientModel(0), clientModel(0),
@ -550,7 +553,7 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(bitcoin); Q_INIT_RESOURCE(bitcoin);
Q_INIT_RESOURCE(bitcoin_locale); Q_INIT_RESOURCE(bitcoin_locale);
BitcoinApplication app(argc, argv); BitcoinApplication app;
#if QT_VERSION > 0x050100 #if QT_VERSION > 0x050100
// Generate high-dpi pixmaps // Generate high-dpi pixmaps
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

View file

@ -33,6 +33,9 @@ Q_IMPORT_PLUGIN(qkrcodecs)
extern void noui_connect(); extern void noui_connect();
static int qt_argc = 1;
static const char* qt_argv = "dogecoin-qt";
// This is all you need to run all the tests // This is all you need to run all the tests
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -46,7 +49,7 @@ int main(int argc, char *argv[])
// Don't remove this, it's needed to access // Don't remove this, it's needed to access
// QCoreApplication:: in the tests // QCoreApplication:: in the tests
QCoreApplication app(argc, argv); QCoreApplication app(qt_argc, const_cast<char **>(&qt_argv));
app.setApplicationName("Bitcoin-Qt-test"); app.setApplicationName("Bitcoin-Qt-test");
SSL_library_init(); SSL_library_init();