Browse Source

Merge pull request #7316 from evsh/plugin-version-crash-fix

Fix ignoring of incorrect version strings in search plugins. Closes #7101
adaptive-webui-19844
sledgehammer999 7 years ago committed by GitHub
parent
commit
42b811e578
  1. 12
      src/base/searchengine.cpp
  2. 2
      src/base/utils/version.h

12
src/base/searchengine.cpp

@ -36,6 +36,7 @@
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/logger.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
@ -669,13 +670,20 @@ PluginVersion SearchEngine::getPluginVersion(QString filePath)
if (!plugin.open(QIODevice::ReadOnly | QIODevice::Text)) if (!plugin.open(QIODevice::ReadOnly | QIODevice::Text))
return {}; return {};
const PluginVersion invalidVersion;
PluginVersion version; PluginVersion version;
while (!plugin.atEnd()) { while (!plugin.atEnd()) {
QByteArray line = plugin.readLine(); QByteArray line = plugin.readLine();
if (line.startsWith("#VERSION: ")) { if (line.startsWith("#VERSION: ")) {
line = line.split(' ').last().trimmed(); line = line.split(' ').last().trimmed();
version = PluginVersion::tryParse(line, {}); version = PluginVersion::tryParse(line, invalidVersion);
qDebug() << "plugin" << filePath << "version: " << version; if (version == invalidVersion) {
LogMsg(tr("Search plugin '%1' contains invalid version string ('%2')")
.arg(Utils::Fs::fileName(filePath)).arg(QString::fromUtf8(line)), Log::MsgType::WARNING);
}
else
qDebug() << "plugin" << filePath << "version: " << version;
break; break;
} }
} }

2
src/base/utils/version.h

@ -117,7 +117,7 @@ namespace Utils
{ {
// find the last one non-zero component // find the last one non-zero component
std::size_t lastSignificantIndex = N - 1; std::size_t lastSignificantIndex = N - 1;
while (lastSignificantIndex >= 0 && (*this)[lastSignificantIndex] == 0) while (lastSignificantIndex > 0 && (*this)[lastSignificantIndex] == 0)
--lastSignificantIndex; --lastSignificantIndex;
if (lastSignificantIndex + 1 < Mandatory) // lastSignificantIndex >= 0 if (lastSignificantIndex + 1 < Mandatory) // lastSignificantIndex >= 0

Loading…
Cancel
Save