Cleanup IStorageAccessor validation code

This commit is contained in:
Billy Laws 2021-09-17 19:45:47 +01:00
parent 83eb88d78b
commit 4a7700bd7c

View File

@ -14,11 +14,12 @@ namespace skyline::service::am {
Result IStorageAccessor::Write(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto offset{request.Pop<i64>()};
auto size{std::min(static_cast<i64>(request.inputBuf.at(0).size()), static_cast<i64>(parent->content.size()) - offset)};
if (offset > parent->content.size())
if (offset < 0 || offset > parent->content.size())
return result::OutOfBounds;
auto size{std::min(static_cast<i64>(request.inputBuf.at(0).size()), static_cast<i64>(parent->content.size()) - offset)};
if (size)
span(parent->content).copy_from(request.inputBuf.at(0), size);
@ -27,12 +28,13 @@ namespace skyline::service::am {
Result IStorageAccessor::Read(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto offset{request.Pop<i64>()};
auto size{std::min(static_cast<i64>(request.outputBuf.at(0).size()), static_cast<i64>(parent->content.size()) - offset)};
if (offset > parent->content.size())
if (offset < 0 || offset > parent->content.size())
return result::OutOfBounds;
if (size > 0)
auto size{std::min(static_cast<i64>(request.outputBuf.at(0).size()), static_cast<i64>(parent->content.size()) - offset)};
if (size)
request.outputBuf.at(0).copy_from(span(parent->content.data() + offset, size));
return {};