Skip to content

Commit

Permalink
vfs: Fix bounds check on kmesg read
Browse files Browse the repository at this point in the history
  • Loading branch information
marv7000 committed Dec 23, 2024
1 parent 2aea7fc commit b427514
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kernel/fs/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ usize kmesg_cap;

isize terminal_kmesg_read(Handle* self, FileDescriptor* fd, void* output_buffer, usize amount, off_t offset)
{
if (amount > kmesg_len)
amount = kmesg_len;
if (offset > kmesg_len)
return 0;

if (offset + amount > kmesg_len)
amount = kmesg_len - offset;

memcpy(output_buffer, kmesg_buffer + offset, amount);
return amount;
Expand Down

0 comments on commit b427514

Please sign in to comment.