From 6368d8063a6a1179218c8b46bd355c240f603255 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 6 Mar 2022 19:13:05 -0800 Subject: [PATCH] fs: add just in case bounds checking to linux/macos dirent read --- .../source/fssystem/fssystem_local_file_system.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/libstratosphere/source/fssystem/fssystem_local_file_system.cpp b/libraries/libstratosphere/source/fssystem/fssystem_local_file_system.cpp index 8571a5fc8..1a6bcc477 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_local_file_system.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_local_file_system.cpp @@ -746,6 +746,8 @@ namespace ams::fssystem { std::memset(out_entry->name, 0, sizeof(out_entry->name)); const auto name_len = std::strlen(ent->d_name); + AMS_ABORT_UNLESS(name_len <= fs::EntryNameLengthMax); + std::memcpy(out_entry->name, ent->d_name, name_len + 1); out_entry->type = (ent->d_type == DT_DIR) ? fs::DirectoryEntryType_Directory : fs::DirectoryEntryType_File; @@ -753,6 +755,7 @@ namespace ams::fssystem { /* If we have to, get the filesize. This is (unfortunately) expensive on linux. */ if (out_entry->type == fs::DirectoryEntryType_File && !m_not_require_file_size) { /* Set up the temporary file path. */ + AMS_ABORT_UNLESS(base_path_len + name_len + 1 <= PATH_MAX); std::memcpy(path_buf + base_path_len, ent->d_name, name_len + 1); /* Get the file stats. */