1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-27 14:22:17 +00:00

strat: minor result/overflow check fixes

This commit is contained in:
Michael Scire 2022-03-13 03:30:17 -07:00
parent 82620f95a3
commit 6e6b86eabc
3 changed files with 11 additions and 19 deletions

View file

@ -39,9 +39,7 @@ namespace ams::fs::fsa {
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
R_UNLESS(offset >= 0, fs::ResultOutOfRange()); R_UNLESS(offset >= 0, fs::ResultOutOfRange());
R_UNLESS(util::IsIntValueRepresentable<s64>(size), fs::ResultOutOfRange()); R_UNLESS(util::IsIntValueRepresentable<s64>(size), fs::ResultOutOfRange());
R_UNLESS(util::CanAddWithoutOverflow<s64>(offset, size), fs::ResultOutOfRange());
const s64 signed_size = static_cast<s64>(size);
R_UNLESS((std::numeric_limits<s64>::max() - offset) >= signed_size, fs::ResultOutOfRange());
/* Do the read. */ /* Do the read. */
R_RETURN(this->DoRead(out, offset, buffer, size, option)); R_RETURN(this->DoRead(out, offset, buffer, size, option));
@ -71,9 +69,7 @@ namespace ams::fs::fsa {
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument()); R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
R_UNLESS(offset >= 0, fs::ResultOutOfRange()); R_UNLESS(offset >= 0, fs::ResultOutOfRange());
R_UNLESS(util::IsIntValueRepresentable<s64>(size), fs::ResultOutOfRange()); R_UNLESS(util::IsIntValueRepresentable<s64>(size), fs::ResultOutOfRange());
R_UNLESS(util::CanAddWithoutOverflow<s64>(offset, size), fs::ResultOutOfRange());
const s64 signed_size = static_cast<s64>(size);
R_UNLESS((std::numeric_limits<s64>::max() - offset) >= signed_size, fs::ResultOutOfRange());
R_RETURN(this->DoWrite(offset, buffer, size, option)); R_RETURN(this->DoWrite(offset, buffer, size, option));
} }

View file

@ -157,11 +157,7 @@ namespace ams::time::impl::util {
R_UNLESS(out != nullptr, time::ResultInvalidPointer()); R_UNLESS(out != nullptr, time::ResultInvalidPointer());
R_UNLESS(from.source_id == to.source_id, time::ResultNotComparable()); R_UNLESS(from.source_id == to.source_id, time::ResultNotComparable());
const bool no_overflow = (from.value >= 0 ? (to.value >= std::numeric_limits<s64>::min() + from.value) R_UNLESS(ams::util::TrySubtractWithoutOverflow(out, to.value, from.value), time::ResultOverflowed());
: (to.value <= std::numeric_limits<s64>::max() + from.value));
R_UNLESS(no_overflow, time::ResultOverflowed());
*out = to.value - from.value;
return ResultSuccess(); return ResultSuccess();
} }

View file

@ -123,7 +123,7 @@ namespace ams::mitm::sysupdater {
/* Open the file storage. */ /* Open the file storage. */
std::shared_ptr<ams::fs::FileStorageBasedFileSystem> file_storage = fssystem::AllocateShared<ams::fs::FileStorageBasedFileSystem>(); std::shared_ptr<ams::fs::FileStorageBasedFileSystem> file_storage = fssystem::AllocateShared<ams::fs::FileStorageBasedFileSystem>();
R_UNLESS(file_storage != nullptr, fs::ResultAllocationMemoryFailedInFileSystemProxyCoreImplD()); R_UNLESS(file_storage != nullptr, fs::ResultAllocationMemoryFailedInNcaFileSystemServiceImplA());
R_TRY(file_storage->Initialize(std::move(base_fs), nsp_path, ams::fs::OpenMode_Read)); R_TRY(file_storage->Initialize(std::move(base_fs), nsp_path, ams::fs::OpenMode_Read));
/* Create a partition fs. */ /* Create a partition fs. */
@ -138,7 +138,7 @@ namespace ams::mitm::sysupdater {
Result ParseNca(const char **path, std::shared_ptr<fssystem::NcaReader> *out, std::shared_ptr<ams::fs::fsa::IFileSystem> base_fs) { Result ParseNca(const char **path, std::shared_ptr<fssystem::NcaReader> *out, std::shared_ptr<ams::fs::fsa::IFileSystem> base_fs) {
/* Open the file storage. */ /* Open the file storage. */
std::shared_ptr<ams::fs::FileStorageBasedFileSystem> file_storage = fssystem::AllocateShared<ams::fs::FileStorageBasedFileSystem>(); std::shared_ptr<ams::fs::FileStorageBasedFileSystem> file_storage = fssystem::AllocateShared<ams::fs::FileStorageBasedFileSystem>();
R_UNLESS(file_storage != nullptr, fs::ResultAllocationMemoryFailedInFileSystemProxyCoreImplE()); R_UNLESS(file_storage != nullptr, fs::ResultAllocationMemoryFailedInNcaFileSystemServiceImplB());
/* Get the nca path. */ /* Get the nca path. */
ams::fs::Path nca_path; ams::fs::Path nca_path;