From 29e89a395007b02f33ed14e2c5768acecf8ba4ad Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 30 Oct 2022 16:29:39 +0000 Subject: [PATCH] Fix crashes when opening non-existent directories --- app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp | 2 ++ app/src/main/cpp/skyline/vfs/filesystem.h | 6 +----- app/src/main/cpp/skyline/vfs/os_filesystem.cpp | 7 ++++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp b/app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp index f8617d27..f70e37bb 100644 --- a/app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp +++ b/app/src/main/cpp/skyline/services/fssrv/IFileSystem.cpp @@ -61,6 +61,8 @@ namespace skyline::service::fssrv { auto listMode{request.Pop()}; auto directory{backing->OpenDirectory(path, listMode)}; + if (!directory) + return result::PathDoesNotExist; manager.RegisterService(std::make_shared(std::move(directory), backing, state, manager), session, response); return {}; diff --git a/app/src/main/cpp/skyline/vfs/filesystem.h b/app/src/main/cpp/skyline/vfs/filesystem.h index 53e80068..7b424ca7 100644 --- a/app/src/main/cpp/skyline/vfs/filesystem.h +++ b/app/src/main/cpp/skyline/vfs/filesystem.h @@ -134,11 +134,7 @@ namespace skyline::vfs { * @return A shared pointer to a Directory object of the directory */ std::shared_ptr OpenDirectory(const std::string &path, Directory::ListMode listMode = {true, true}) { - auto dir{OpenDirectoryUnchecked(path, listMode)}; - if (dir == nullptr) - throw exception("Failed to open directory: {}", path); - - return dir; + return OpenDirectoryUnchecked(path, listMode); }; }; } diff --git a/app/src/main/cpp/skyline/vfs/os_filesystem.cpp b/app/src/main/cpp/skyline/vfs/os_filesystem.cpp index f1889636..e20ce889 100644 --- a/app/src/main/cpp/skyline/vfs/os_filesystem.cpp +++ b/app/src/main/cpp/skyline/vfs/os_filesystem.cpp @@ -84,7 +84,12 @@ namespace skyline::vfs { } std::shared_ptr OsFileSystem::OpenDirectoryImpl(const std::string &path, Directory::ListMode listMode) { - return std::make_shared(basePath + path, listMode); + struct dirent *entry; + auto directory{opendir((basePath + path).c_str())}; + if (!directory) + return nullptr; + else + return std::make_shared(basePath + path, listMode); } OsFileSystemDirectory::OsFileSystemDirectory(std::string path, Directory::ListMode listMode) : Directory(listMode), path(std::move(path)) {}