From 69551efde35c6ac734b632c3a67dbbc562ce264b Mon Sep 17 00:00:00 2001 From: tobtoht Date: Fri, 5 Feb 2021 19:43:14 +0100 Subject: [PATCH] Tor: properly overwrite old binary --- src/utils/tor.cpp | 8 ++++++-- src/utils/tor.h | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils/tor.cpp b/src/utils/tor.cpp index 475f459..d1ab811 100644 --- a/src/utils/tor.cpp +++ b/src/utils/tor.cpp @@ -211,8 +211,12 @@ bool Tor::unpackBins() { TorVersion embeddedVersion = this->stringToVersion(QString(TOR_VERSION)); TorVersion filesystemVersion = this->getVersion(torPath); qDebug() << QString("Tor versions: embedded %1, filesystem %2").arg(embeddedVersion.toString(), filesystemVersion.toString()); - if (embeddedVersion > filesystemVersion) { - QFile::remove(torPath); + if (TorVersion::isValid(filesystemVersion) && (embeddedVersion > filesystemVersion)) { + qInfo() << "Embedded version is newer, overwriting."; + QFile::setPermissions(torPath, QFile::ReadOther | QFile::WriteOther); + if (!QFile::remove(torPath)) { + qWarning() << "Unable to remove old Tor binary"; + }; } qDebug() << "Writing Tor executable to " << this->torPath; diff --git a/src/utils/tor.h b/src/utils/tor.h index 22f0e35..22ab243 100644 --- a/src/utils/tor.h +++ b/src/utils/tor.h @@ -54,6 +54,10 @@ struct TorVersion QString::number(patch), QString::number(release)); } + static bool isValid(const TorVersion &v) { + return v != TorVersion(); + } + int major; int minor; int patch;