mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Kernel: Check for off_t overflow before reading/writing InodeFile
Let's double-check before calling the Inode. This way we don't have to trust every Inode subclass to validate user-supplied inputs.
This commit is contained in:
parent
342b787d1c
commit
9f05044c50
Notes:
sideshowbarker
2024-07-18 22:36:42 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9f05044c50d
1 changed files with 6 additions and 0 deletions
|
@ -48,6 +48,9 @@ InodeFile::~InodeFile()
|
|||
|
||||
KResultOr<size_t> InodeFile::read(FileDescription& description, size_t offset, UserOrKernelBuffer& buffer, size_t count)
|
||||
{
|
||||
if (Checked<off_t>::addition_would_overflow(offset, count))
|
||||
return EOVERFLOW;
|
||||
|
||||
ssize_t nread = m_inode->read_bytes(offset, count, buffer, &description);
|
||||
if (nread > 0) {
|
||||
Thread::current()->did_file_read(nread);
|
||||
|
@ -60,6 +63,9 @@ KResultOr<size_t> InodeFile::read(FileDescription& description, size_t offset, U
|
|||
|
||||
KResultOr<size_t> InodeFile::write(FileDescription& description, size_t offset, const UserOrKernelBuffer& data, size_t count)
|
||||
{
|
||||
if (Checked<off_t>::addition_would_overflow(offset, count))
|
||||
return EOVERFLOW;
|
||||
|
||||
ssize_t nwritten = m_inode->write_bytes(offset, count, data, &description);
|
||||
if (nwritten > 0) {
|
||||
m_inode->set_mtime(kgettimeofday().tv_sec);
|
||||
|
|
Loading…
Reference in a new issue