From b0554938947e72ec93ec7291e6637cf0c7f083be Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 10 Sep 2022 11:12:48 +0200 Subject: [PATCH] Fixed an issue where multiple levels of symlinking in the ROMs directory tree could crash the application on startup. --- es-app/src/SystemData.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index 57c372688..94e856dd9 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -347,20 +347,23 @@ bool SystemData::populateFolder(FileData* folder) // Make sure that it's not a recursive symlink pointing to a location higher in the // hierarchy as the application would run forever trying to resolve the link. if (Utils::FileSystem::isSymlink(filePath)) { - const std::string canonicalPath = Utils::FileSystem::getCanonicalPath(filePath); - const std::string canonicalStartPath = - Utils::FileSystem::getCanonicalPath(mEnvData->mStartPath); - const std::string combinedPath = - mEnvData->mStartPath + - canonicalPath.substr(canonicalStartPath.size(), - canonicalStartPath.size() - canonicalPath.size()); - if (filePath.find(combinedPath) == 0) { - LOG(LogWarning) << "Skipped \"" << filePath << "\" as it's a recursive symlink"; - continue; + const std::string canonicalPath {Utils::FileSystem::getCanonicalPath(filePath)}; + const std::string canonicalStartPath { + Utils::FileSystem::getCanonicalPath(mEnvData->mStartPath)}; + if (canonicalPath.size() >= canonicalStartPath.size()) { + const std::string combinedPath { + mEnvData->mStartPath + + canonicalPath.substr(canonicalStartPath.size(), + canonicalStartPath.size() - canonicalPath.size())}; + if (filePath.find(combinedPath) == 0) { + LOG(LogWarning) + << "Skipped \"" << filePath << "\" as it's a recursive symlink"; + continue; + } } } - FileData* newFolder = new FileData(FOLDER, filePath, mEnvData, this); + FileData* newFolder {new FileData(FOLDER, filePath, mEnvData, this)}; populateFolder(newFolder); if (mFlattenFolders) {