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()) {
mEnvData->mStartPath + const std::string combinedPath {
canonicalPath.substr(canonicalStartPath.size(), mEnvData->mStartPath +
canonicalStartPath.size() - canonicalPath.size()); canonicalPath.substr(canonicalStartPath.size(),
if (filePath.find(combinedPath) == 0) { canonicalStartPath.size() - canonicalPath.size())};
LOG(LogWarning) << "Skipped \"" << filePath << "\" as it's a recursive symlink"; if (filePath.find(combinedPath) == 0) {
continue; 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); populateFolder(newFolder);
if (mFlattenFolders) { if (mFlattenFolders) {