Skip to content

Commit 155a7f7

Browse files
committed
Update beforeLoadPlugins to refuse to load plugins the name of which does not match the pattern
1 parent 356947b commit 155a7f7

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/app/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QtCore/QProcess>
44
#include <QtCore/QSettings>
55
#include <QtCore/QLoggingCategory>
6+
#include <QtCore/QRegularExpression>
67
#include <QtGui/QWindow>
78
#include <QtNetwork/QNetworkProxyFactory>
89
#include <QtWidgets/QApplication>
@@ -17,6 +18,9 @@
1718
#include <CoreApi/logger.h>
1819
#include <CoreApi/translationmanager.h>
1920

21+
#include <extensionsystem/pluginmanager.h>
22+
#include <extensionsystem/pluginspec.h>
23+
2024
#include <qjsonsettings.h>
2125

2226
#include <SVSCraftFluentSystemIcons/FluentSystemIconsImageProvider.h>
@@ -26,6 +30,8 @@
2630
#include <application_config.h>
2731
#include <application_buildinfo.h>
2832

33+
#include <extensionsystem/pluginspec.h>
34+
2935
#ifdef APPLICATION_ENABLE_BREAKPAD
3036
# include <QBreakpadHandler.h>
3137
#endif
@@ -119,6 +125,13 @@ class MyLoaderSpec : public Loader::LoaderSpec {
119125
RuntimeInterface::translationManager()->addTranslationPath(translationBaseDir + QStringLiteral("/svscraft/translations"));
120126
RuntimeInterface::translationManager()->addTranslationPath(translationBaseDir + QStringLiteral("/uishell/translations"));
121127

128+
for (auto pluginSpec : ExtensionSystem::PluginManager::plugins()) {
129+
static QRegularExpression rx("^([a-z_][a-z0-9_]*)(\\.[a-z_][a-z0-9_]*)+$");
130+
if (!rx.match(pluginSpec->name()).hasMatch()) {
131+
qFatal() << "Refused to load due to an invalid plugin name:" << pluginSpec->name() << "Plugin name should match" << rx.pattern();
132+
}
133+
}
134+
122135
bool lastInitializationWarningSuppressed = QApplication::arguments().contains(kNoWarningLastInitialization);
123136
if (settings->value("lastInitializationAbortedFlag").toBool() && !lastInitializationWarningSuppressed) {
124137
qInfo() << "Last initialization was aborted abnormally";

0 commit comments

Comments
 (0)