Browse Source

Fix ignoring of incorrect version strings in search plugins. Closes #7101.

Printing of Version with all components set to zero was segfaulting due
to underflow in array index. Also add log message for such plugins.
adaptive-webui-19844
Eugene Shalygin 7 years ago
parent
commit
ef1597e45b
  1. 12
      src/base/searchengine.cpp
  2. 2
      src/base/utils/version.h

12
src/base/searchengine.cpp

@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/logger.h"
#include "base/preferences.h"
#include "base/profile.h"
#include "base/net/downloadmanager.h"
@ -669,13 +670,20 @@ PluginVersion SearchEngine::getPluginVersion(QString filePath) @@ -669,13 +670,20 @@ PluginVersion SearchEngine::getPluginVersion(QString filePath)
if (!plugin.open(QIODevice::ReadOnly | QIODevice::Text))
return {};
const PluginVersion invalidVersion;
PluginVersion version;
while (!plugin.atEnd()) {
QByteArray line = plugin.readLine();
if (line.startsWith("#VERSION: ")) {
line = line.split(' ').last().trimmed();
version = PluginVersion::tryParse(line, {});
qDebug() << "plugin" << filePath << "version: " << version;
version = PluginVersion::tryParse(line, invalidVersion);
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;
}
}

2
src/base/utils/version.h

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

Loading…
Cancel
Save