diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_istorage.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_istorage.hpp index d6749c5c3..7a837242d 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_istorage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_istorage.hpp @@ -40,25 +40,25 @@ namespace ams::fs { return this->OperateRange(nullptr, 0, op_id, offset, size, nullptr, 0); } public: - static inline bool IsRangeValid(s64 offset, s64 size, s64 total_size) { + static inline bool CheckAccessRange(s64 offset, s64 size, s64 total_size) { return offset >= 0 && size >= 0 && size <= total_size && offset <= (total_size - size); } - static inline bool IsRangeValid(s64 offset, size_t size, s64 total_size) { - return IsRangeValid(offset, static_cast(size), total_size); + static inline bool CheckAccessRange(s64 offset, size_t size, s64 total_size) { + return CheckAccessRange(offset, static_cast(size), total_size); } - static inline bool IsOffsetAndSizeValid(s64 offset, s64 size) { + static inline bool CheckOffsetAndSize(s64 offset, s64 size) { return offset >= 0 && size >= 0 && offset <= (offset + size); } - static inline bool IsOffsetAndSizeValid(s64 offset, size_t size) { - return IsOffsetAndSizeValid(offset, static_cast(size)); + static inline bool CheckOffsetAndSize(s64 offset, size_t size) { + return CheckOffsetAndSize(offset, static_cast(size)); } }; diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_memory_storage.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_memory_storage.hpp index b897c535e..9cc59e790 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_memory_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_memory_storage.hpp @@ -32,8 +32,8 @@ namespace ams::fs { R_SUCCEED_IF(size == 0); /* Validate arguments. */ - R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); - R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange()); + R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); /* Copy from memory. */ std::memcpy(buffer, this->buf + offset, size); @@ -45,8 +45,8 @@ namespace ams::fs { R_SUCCEED_IF(size == 0); /* Validate arguments. */ - R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); - R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange()); + R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); /* Copy to memory. */ std::memcpy(this->buf + offset, buffer, size); diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_substorage.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_substorage.hpp index 4e39ae361..08ac3cf7b 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_substorage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_substorage.hpp @@ -77,8 +77,8 @@ namespace ams::fs { /* Validate arguments and read. */ - R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); - R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange()); + R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); return this->base_storage->Read(this->offset + offset, buffer, size); } @@ -90,8 +90,8 @@ namespace ams::fs { R_SUCCEED_IF(size == 0); /* Validate arguments and write. */ - R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); - R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange()); + R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); return this->base_storage->Write(this->offset + offset, buffer, size); } @@ -102,9 +102,9 @@ namespace ams::fs { virtual Result SetSize(s64 size) override { /* Ensure we're initialized and validate arguments. */ - R_UNLESS(this->IsValid(), fs::ResultNotInitialized()); - R_UNLESS(this->resizable, fs::ResultUnsupportedOperationInSubStorageA()); - R_UNLESS(IStorage::IsOffsetAndSizeValid(this->offset, size), fs::ResultInvalidSize()); + R_UNLESS(this->IsValid(), fs::ResultNotInitialized()); + R_UNLESS(this->resizable, fs::ResultUnsupportedOperationInSubStorageA()); + R_UNLESS(IStorage::CheckOffsetAndSize(this->offset, size), fs::ResultInvalidSize()); /* Ensure that we're allowed to set size. */ s64 cur_size; @@ -134,7 +134,7 @@ namespace ams::fs { R_SUCCEED_IF(size == 0); /* Validate arguments and operate. */ - R_UNLESS(IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange()); + R_UNLESS(IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange()); return this->base_storage->OperateRange(dst, dst_size, op_id, this->offset + offset, size, src, src_size); } diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_alignment_matching_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_alignment_matching_storage.hpp index 2ff67cea3..ba3a92194 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_alignment_matching_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_alignment_matching_storage.hpp @@ -61,7 +61,7 @@ namespace ams::fssystem { s64 bs_size = 0; R_TRY(this->GetSize(std::addressof(bs_size))); - R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange()); + R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange()); return AlignmentMatchingStorageImpl::Read(this->base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast(buffer), size); } @@ -79,7 +79,7 @@ namespace ams::fssystem { s64 bs_size = 0; R_TRY(this->GetSize(std::addressof(bs_size))); - R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange()); + R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange()); return AlignmentMatchingStorageImpl::Write(this->base_storage, work_buf, sizeof(work_buf), DataAlign, BufferAlign, offset, static_cast(buffer), size); } @@ -115,7 +115,7 @@ namespace ams::fssystem { /* Get the base storage size. */ s64 bs_size = 0; R_TRY(this->GetSize(std::addressof(bs_size))); - R_UNLESS(fs::IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange()); + R_UNLESS(fs::IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange()); /* Operate on the base storage. */ const auto valid_size = std::min(size, bs_size - offset); @@ -154,7 +154,7 @@ namespace ams::fssystem { s64 bs_size = 0; R_TRY(this->GetSize(std::addressof(bs_size))); - R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange()); + R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange()); /* Allocate a pooled buffer. */ PooledBuffer pooled_buffer; @@ -172,7 +172,7 @@ namespace ams::fssystem { s64 bs_size = 0; R_TRY(this->GetSize(std::addressof(bs_size))); - R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange()); + R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange()); /* Allocate a pooled buffer. */ PooledBuffer pooled_buffer; @@ -212,7 +212,7 @@ namespace ams::fssystem { /* Get the base storage size. */ s64 bs_size = 0; R_TRY(this->GetSize(std::addressof(bs_size))); - R_UNLESS(fs::IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange()); + R_UNLESS(fs::IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange()); /* Operate on the base storage. */ const auto valid_size = std::min(size, bs_size - offset); @@ -257,7 +257,7 @@ namespace ams::fssystem { s64 bs_size = 0; R_TRY(this->GetSize(std::addressof(bs_size))); - R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange()); + R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange()); /* Allocate a pooled buffer. */ PooledBuffer pooled_buffer(this->data_align, this->data_align); @@ -294,7 +294,7 @@ namespace ams::fssystem { /* Get the base storage size. */ s64 bs_size = 0; R_TRY(this->GetSize(std::addressof(bs_size))); - R_UNLESS(fs::IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange()); + R_UNLESS(fs::IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange()); /* Operate on the base storage. */ const auto valid_size = std::min(size, bs_size - offset); diff --git a/libraries/libstratosphere/source/fs/fs_file_storage.cpp b/libraries/libstratosphere/source/fs/fs_file_storage.cpp index b56153fb0..d0401bb3d 100644 --- a/libraries/libstratosphere/source/fs/fs_file_storage.cpp +++ b/libraries/libstratosphere/source/fs/fs_file_storage.cpp @@ -33,7 +33,7 @@ namespace ams::fs { R_TRY(this->UpdateSize()); /* Ensure our access is valid. */ - R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); size_t read_size; return this->base_file->Read(&read_size, offset, buffer, size); @@ -50,7 +50,7 @@ namespace ams::fs { R_TRY(this->UpdateSize()); /* Ensure our access is valid. */ - R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); return this->base_file->Write(offset, buffer, size, fs::WriteOption()); } @@ -83,7 +83,7 @@ namespace ams::fs { return ResultSuccess(); } R_TRY(this->UpdateSize()); - R_UNLESS(IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange()); + R_UNLESS(IStorage::CheckOffsetAndSize(offset, size), fs::ResultOutOfRange()); return this->base_file->OperateRange(dst, dst_size, op_id, offset, size, src, src_size); default: return fs::ResultUnsupportedOperationInFileStorageA(); @@ -121,7 +121,7 @@ namespace ams::fs { R_TRY(this->UpdateSize()); /* Ensure our access is valid. */ - R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); return ReadFile(this->handle, offset, buffer, size, fs::ReadOption()); } @@ -140,7 +140,7 @@ namespace ams::fs { R_TRY(this->UpdateSize()); /* Ensure our access is valid. */ - R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, this->size), fs::ResultOutOfRange()); return WriteFile(this->handle, offset, buffer, size, fs::WriteOption()); } diff --git a/libraries/libstratosphere/source/fssystem/fssystem_alignment_matching_storage_impl.cpp b/libraries/libstratosphere/source/fssystem/fssystem_alignment_matching_storage_impl.cpp index 920e8a2e8..eb5b2cfc5 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_alignment_matching_storage_impl.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_alignment_matching_storage_impl.cpp @@ -197,7 +197,7 @@ namespace ams::fssystem { s64 bs_size = 0; R_TRY(this->GetSize(std::addressof(bs_size))); - R_UNLESS(fs::IStorage::IsRangeValid(offset, size, bs_size), fs::ResultOutOfRange()); + R_UNLESS(fs::IStorage::CheckAccessRange(offset, size, bs_size), fs::ResultOutOfRange()); /* Determine extents. */ const auto offset_end = offset + static_cast(size); diff --git a/libraries/libstratosphere/source/fssystem/save/fssystem_integrity_verification_storage.cpp b/libraries/libstratosphere/source/fssystem/save/fssystem_integrity_verification_storage.cpp index c2f5737b0..18003dded 100644 --- a/libraries/libstratosphere/source/fssystem/save/fssystem_integrity_verification_storage.cpp +++ b/libraries/libstratosphere/source/fssystem/save/fssystem_integrity_verification_storage.cpp @@ -86,7 +86,7 @@ namespace ams::fssystem::save { R_UNLESS(offset <= data_size, fs::ResultInvalidOffset()); /* Validate the access range. */ - R_UNLESS(IStorage::IsRangeValid(offset, size, util::AlignUp(data_size, static_cast(this->verification_block_size))), fs::ResultOutOfRange()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, util::AlignUp(data_size, static_cast(this->verification_block_size))), fs::ResultOutOfRange()); /* Determine the read extents. */ size_t read_size = size; @@ -164,8 +164,8 @@ namespace ams::fssystem::save { R_SUCCEED_IF(size == 0); /* Validate arguments. */ - R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); - R_UNLESS(IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultInvalidOffset()); + R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); + R_UNLESS(IStorage::CheckOffsetAndSize(offset, size), fs::ResultInvalidOffset()); /* Validate the offset. */ s64 data_size; @@ -173,7 +173,7 @@ namespace ams::fssystem::save { R_UNLESS(offset < data_size, fs::ResultInvalidOffset()); /* Validate the access range. */ - R_UNLESS(IStorage::IsRangeValid(offset, size, util::AlignUp(data_size, static_cast(this->verification_block_size))), fs::ResultOutOfRange()); + R_UNLESS(IStorage::CheckAccessRange(offset, size, util::AlignUp(data_size, static_cast(this->verification_block_size))), fs::ResultOutOfRange()); /* Validate preconditions. */ AMS_ASSERT(util::IsAligned(offset, this->verification_block_size));