1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

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

Fix ignoring of incorrect version strings in search plugins. Closes #7101
This commit is contained in:
sledgehammer999 2017-08-21 00:18:19 +03:00 committed by GitHub
commit 42b811e578
2 changed files with 11 additions and 3 deletions

View File

@ -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)
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;
}
}

View File

@ -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