mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 21:03:30 -07:00
Don't leak parent file descriptors to child processes
It is unexpected for the child process to inherit parent file descriptors. Requires Qt >= 6.6 and only affects Linux. Closes #10312. PR #22457.
This commit is contained in:
parent
627d89813c
commit
d21653e8cf
6 changed files with 20 additions and 3 deletions
|
@ -674,6 +674,9 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo
|
||||||
QProcess proc;
|
QProcess proc;
|
||||||
proc.setProgram(command);
|
proc.setProgram(command);
|
||||||
proc.setArguments(args);
|
proc.setArguments(args);
|
||||||
|
#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
|
||||||
|
proc.setUnixProcessParameters(QProcess::UnixProcessFlag::CloseFileDescriptors);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (proc.startDetached())
|
if (proc.startDetached())
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,9 @@ SearchDownloadHandler::SearchDownloadHandler(const QString &pluginName, const QS
|
||||||
, m_downloadProcess {new QProcess(this)}
|
, m_downloadProcess {new QProcess(this)}
|
||||||
{
|
{
|
||||||
m_downloadProcess->setEnvironment(QProcess::systemEnvironment());
|
m_downloadProcess->setEnvironment(QProcess::systemEnvironment());
|
||||||
|
#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
|
||||||
|
m_downloadProcess->setUnixProcessParameters(QProcess::UnixProcessFlag::CloseFileDescriptors);
|
||||||
|
#endif
|
||||||
connect(m_downloadProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished)
|
connect(m_downloadProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished)
|
||||||
, this, &SearchDownloadHandler::downloadProcessFinished);
|
, this, &SearchDownloadHandler::downloadProcessFinished);
|
||||||
const QStringList params
|
const QStringList params
|
||||||
|
|
|
@ -71,6 +71,10 @@ SearchHandler::SearchHandler(const QString &pattern, const QString &category, co
|
||||||
{
|
{
|
||||||
// Load environment variables (proxy)
|
// Load environment variables (proxy)
|
||||||
m_searchProcess->setEnvironment(QProcess::systemEnvironment());
|
m_searchProcess->setEnvironment(QProcess::systemEnvironment());
|
||||||
|
m_searchProcess->setProgram(Utils::ForeignApps::pythonInfo().executableName);
|
||||||
|
#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
|
||||||
|
m_searchProcess->setUnixProcessParameters(QProcess::UnixProcessFlag::CloseFileDescriptors);
|
||||||
|
#endif
|
||||||
|
|
||||||
const QStringList params
|
const QStringList params
|
||||||
{
|
{
|
||||||
|
@ -79,9 +83,6 @@ SearchHandler::SearchHandler(const QString &pattern, const QString &category, co
|
||||||
m_usedPlugins.join(u','),
|
m_usedPlugins.join(u','),
|
||||||
m_category
|
m_category
|
||||||
};
|
};
|
||||||
|
|
||||||
// Launch search
|
|
||||||
m_searchProcess->setProgram(Utils::ForeignApps::pythonInfo().executableName);
|
|
||||||
m_searchProcess->setArguments(params + m_pattern.split(u' '));
|
m_searchProcess->setArguments(params + m_pattern.split(u' '));
|
||||||
|
|
||||||
connect(m_searchProcess, &QProcess::errorOccurred, this, &SearchHandler::processFailed);
|
connect(m_searchProcess, &QProcess::errorOccurred, this, &SearchHandler::processFailed);
|
||||||
|
@ -93,6 +94,7 @@ SearchHandler::SearchHandler(const QString &pattern, const QString &category, co
|
||||||
connect(m_searchTimeout, &QTimer::timeout, this, &SearchHandler::cancelSearch);
|
connect(m_searchTimeout, &QTimer::timeout, this, &SearchHandler::cancelSearch);
|
||||||
m_searchTimeout->start(3min);
|
m_searchTimeout->start(3min);
|
||||||
|
|
||||||
|
// Launch search
|
||||||
// deferred start allows clients to handle starting-related signals
|
// deferred start allows clients to handle starting-related signals
|
||||||
QMetaObject::invokeMethod(this, [this]() { m_searchProcess->start(QIODevice::ReadOnly); }
|
QMetaObject::invokeMethod(this, [this]() { m_searchProcess->start(QIODevice::ReadOnly); }
|
||||||
, Qt::QueuedConnection);
|
, Qt::QueuedConnection);
|
||||||
|
|
|
@ -520,6 +520,9 @@ void SearchPluginManager::update()
|
||||||
{
|
{
|
||||||
QProcess nova;
|
QProcess nova;
|
||||||
nova.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
|
nova.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
|
||||||
|
#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
|
||||||
|
nova.setUnixProcessParameters(QProcess::UnixProcessFlag::CloseFileDescriptors);
|
||||||
|
#endif
|
||||||
|
|
||||||
const QStringList params
|
const QStringList params
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,6 +57,9 @@ namespace
|
||||||
info = {};
|
info = {};
|
||||||
|
|
||||||
QProcess proc;
|
QProcess proc;
|
||||||
|
#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
|
||||||
|
proc.setUnixProcessParameters(QProcess::UnixProcessFlag::CloseFileDescriptors);
|
||||||
|
#endif
|
||||||
proc.start(exeName, {u"--version"_s}, QIODevice::ReadOnly);
|
proc.start(exeName, {u"--version"_s}, QIODevice::ReadOnly);
|
||||||
if (proc.waitForFinished() && (proc.exitCode() == QProcess::NormalExit))
|
if (proc.waitForFinished() && (proc.exitCode() == QProcess::NormalExit))
|
||||||
{
|
{
|
||||||
|
|
|
@ -176,6 +176,9 @@ void Utils::Gui::openFolderSelect(const Path &path)
|
||||||
const int lineMaxLength = 64;
|
const int lineMaxLength = 64;
|
||||||
|
|
||||||
QProcess proc;
|
QProcess proc;
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
|
||||||
|
proc.setUnixProcessParameters(QProcess::UnixProcessFlag::CloseFileDescriptors);
|
||||||
|
#endif
|
||||||
proc.start(u"xdg-mime"_s, {u"query"_s, u"default"_s, u"inode/directory"_s});
|
proc.start(u"xdg-mime"_s, {u"query"_s, u"default"_s, u"inode/directory"_s});
|
||||||
proc.waitForFinished();
|
proc.waitForFinished();
|
||||||
const auto output = QString::fromLocal8Bit(proc.readLine(lineMaxLength).simplified());
|
const auto output = QString::fromLocal8Bit(proc.readLine(lineMaxLength).simplified());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue