Fixed an issue where multiple levels of symlinking in the ROMs directory tree could crash the application on startup.

This commit is contained in:
Leon Styhre 2022-09-10 11:12:48 +02:00
parent 8cc3d1aac5
commit b055493894

View file

@ -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 // 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. // hierarchy as the application would run forever trying to resolve the link.
if (Utils::FileSystem::isSymlink(filePath)) { if (Utils::FileSystem::isSymlink(filePath)) {
const std::string canonicalPath = Utils::FileSystem::getCanonicalPath(filePath); const std::string canonicalPath {Utils::FileSystem::getCanonicalPath(filePath)};
const std::string canonicalStartPath = const std::string canonicalStartPath {
Utils::FileSystem::getCanonicalPath(mEnvData->mStartPath); Utils::FileSystem::getCanonicalPath(mEnvData->mStartPath)};
const std::string combinedPath = if (canonicalPath.size() >= canonicalStartPath.size()) {
const std::string combinedPath {
mEnvData->mStartPath + mEnvData->mStartPath +
canonicalPath.substr(canonicalStartPath.size(), canonicalPath.substr(canonicalStartPath.size(),
canonicalStartPath.size() - canonicalPath.size()); canonicalStartPath.size() - canonicalPath.size())};
if (filePath.find(combinedPath) == 0) { if (filePath.find(combinedPath) == 0) {
LOG(LogWarning) << "Skipped \"" << filePath << "\" as it's a recursive symlink"; LOG(LogWarning)
<< "Skipped \"" << filePath << "\" as it's a recursive symlink";
continue; continue;
} }
} }
}
FileData* newFolder = new FileData(FOLDER, filePath, mEnvData, this); FileData* newFolder {new FileData(FOLDER, filePath, mEnvData, this)};
populateFolder(newFolder); populateFolder(newFolder);
if (mFlattenFolders) { if (mFlattenFolders) {