Fix crashes when opening non-existent directories

This commit is contained in:
Billy Laws 2022-10-30 16:29:39 +00:00
parent ec139b3027
commit 29e89a3950
3 changed files with 9 additions and 6 deletions

View File

@ -61,6 +61,8 @@ namespace skyline::service::fssrv {
auto listMode{request.Pop<vfs::Directory::ListMode>()}; auto listMode{request.Pop<vfs::Directory::ListMode>()};
auto directory{backing->OpenDirectory(path, listMode)}; auto directory{backing->OpenDirectory(path, listMode)};
if (!directory)
return result::PathDoesNotExist;
manager.RegisterService(std::make_shared<IDirectory>(std::move(directory), backing, state, manager), session, response); manager.RegisterService(std::make_shared<IDirectory>(std::move(directory), backing, state, manager), session, response);
return {}; return {};

View File

@ -134,11 +134,7 @@ namespace skyline::vfs {
* @return A shared pointer to a Directory object of the directory * @return A shared pointer to a Directory object of the directory
*/ */
std::shared_ptr<Directory> OpenDirectory(const std::string &path, Directory::ListMode listMode = {true, true}) { std::shared_ptr<Directory> OpenDirectory(const std::string &path, Directory::ListMode listMode = {true, true}) {
auto dir{OpenDirectoryUnchecked(path, listMode)}; return OpenDirectoryUnchecked(path, listMode);
if (dir == nullptr)
throw exception("Failed to open directory: {}", path);
return dir;
}; };
}; };
} }

View File

@ -84,6 +84,11 @@ namespace skyline::vfs {
} }
std::shared_ptr<Directory> OsFileSystem::OpenDirectoryImpl(const std::string &path, Directory::ListMode listMode) { std::shared_ptr<Directory> OsFileSystem::OpenDirectoryImpl(const std::string &path, Directory::ListMode listMode) {
struct dirent *entry;
auto directory{opendir((basePath + path).c_str())};
if (!directory)
return nullptr;
else
return std::make_shared<OsFileSystemDirectory>(basePath + path, listMode); return std::make_shared<OsFileSystemDirectory>(basePath + path, listMode);
} }