From 744798dc4a23b731943da090a60e7289e4297000 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Wed, 13 Oct 2021 19:07:18 +0200 Subject: [PATCH] DTLS crash : Use writable location for ZRTP and DTLS certificates paths --- linphone-app/src/app/paths/Paths.cpp | 20 ++++++++++--------- linphone-app/src/app/paths/Paths.hpp | 2 +- .../src/components/core/CoreManager.cpp | 7 +++++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/linphone-app/src/app/paths/Paths.cpp b/linphone-app/src/app/paths/Paths.cpp index 91ec227c6..d60f4fb5d 100644 --- a/linphone-app/src/app/paths/Paths.cpp +++ b/linphone-app/src/app/paths/Paths.cpp @@ -40,11 +40,12 @@ static inline bool dirPathExists (const QString &path) { return dir.exists(); } -static inline bool filePathExists (const QString &path) { +static inline bool filePathExists (const QString &path, const bool& isWritable) { QFileInfo info(path); if (!dirPathExists(info.path())) return false; - + if( isWritable && !info.isWritable()) + return false; QFile file(path); return file.exists(); } @@ -177,10 +178,11 @@ static inline QString getAppPluginsDirPath () { } // ----------------------------------------------------------------------------- -bool Paths::filePathExists (const string &path) { - return filePathExists(Utils::coreStringToAppString(path)); +bool Paths::filePathExists (const string &path, const bool isWritable) { + return filePathExists(Utils::coreStringToAppString(path), isWritable); } + // ----------------------------------------------------------------------------- string Paths::getAssistantConfigDirPath () { @@ -319,7 +321,7 @@ static void migrateConfigurationFile (const QString &oldPath, const QString &new } void migrateFlatpakVersionFiles(){ #ifdef Q_OS_LINUX - if(!filePathExists(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/linphone.db")){ + if(!filePathExists(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/linphone.db", true)){ // Copy all files if linphone.db doesn't exist QString flatpakPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.var/app/com.belledonnecommunications.linphone/data/linphone"; if( QDir().exists(flatpakPath)){ @@ -336,25 +338,25 @@ void migrateGTKVersionFiles(){ : QStandardPaths::writableLocation(QStandardPaths::HomeLocation); QString oldPath = oldBaseDir + "/.linphonerc"; - if (!filePathExists(newPath) && filePathExists(oldPath)) + if (!filePathExists(newPath, false) && filePathExists(oldPath, false)) migrateConfigurationFile(oldPath, newPath); newPath = getAppCallHistoryFilePath(); oldPath = oldBaseDir + "/.linphone-call-history.db"; - if (!filePathExists(newPath) && filePathExists(oldPath)) + if (!filePathExists(newPath, false) && filePathExists(oldPath, false)) migrateFile(oldPath, newPath); newPath = getAppFriendsFilePath(); oldPath = oldBaseDir + "/.linphone-friends.db"; - if (!filePathExists(newPath) && filePathExists(oldPath)) + if (!filePathExists(newPath, false) && filePathExists(oldPath, false)) migrateFile(oldPath, newPath); newPath = getAppMessageHistoryFilePath(); oldPath = oldBaseDir + "/.linphone-history.db"; - if (!filePathExists(newPath) && filePathExists(oldPath)) + if (!filePathExists(newPath, false) && filePathExists(oldPath, false)) migrateFile(oldPath, newPath); } void Paths::migrate () { diff --git a/linphone-app/src/app/paths/Paths.hpp b/linphone-app/src/app/paths/Paths.hpp index 1b29624ae..6cb62a752 100644 --- a/linphone-app/src/app/paths/Paths.hpp +++ b/linphone-app/src/app/paths/Paths.hpp @@ -26,7 +26,7 @@ // ============================================================================= namespace Paths { - bool filePathExists (const std::string &path); + bool filePathExists (const std::string &path, const bool isWritable = false); std::string getAssistantConfigDirPath (); diff --git a/linphone-app/src/components/core/CoreManager.cpp b/linphone-app/src/components/core/CoreManager.cpp index 13b582671..76a741402 100644 --- a/linphone-app/src/components/core/CoreManager.cpp +++ b/linphone-app/src/components/core/CoreManager.cpp @@ -208,12 +208,15 @@ void CoreManager::setDatabasesPaths () { // ----------------------------------------------------------------------------- void CoreManager::setOtherPaths () { - if (mCore->getZrtpSecretsFile().empty() || !Paths::filePathExists(mCore->getZrtpSecretsFile())) + if (mCore->getZrtpSecretsFile().empty() || !Paths::filePathExists(mCore->getZrtpSecretsFile(), true)) mCore->setZrtpSecretsFile(Paths::getZrtpSecretsFilePath()); - if (mCore->getUserCertificatesPath().empty() || !Paths::filePathExists(mCore->getUserCertificatesPath())) + qInfo() << "Using ZrtpSecrets path : " << QString::fromStdString(mCore->getZrtpSecretsFile()); + if (mCore->getUserCertificatesPath().empty() || !Paths::filePathExists(mCore->getUserCertificatesPath(), true)) mCore->setUserCertificatesPath(Paths::getUserCertificatesDirPath()); + qInfo() << "Using UserCertificate path : " << QString::fromStdString(mCore->getUserCertificatesPath()); if (mCore->getRootCa().empty() || !Paths::filePathExists(mCore->getRootCa())) mCore->setRootCa(Paths::getRootCaFilePath()); + qInfo() << "Using RootCa path : " << QString::fromStdString(mCore->getRootCa()); } void CoreManager::setResourcesPaths () {