mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +00:00
Kernel: Validate ftruncate(fd, length) syscall inputs
- EINVAL if 'length' is negative - EBADF if 'fd' is not open for writing
This commit is contained in:
parent
bb9db9d430
commit
6a4b376021
2 changed files with 24 additions and 1 deletions
|
@ -3424,10 +3424,13 @@ int Process::sys$rename(const char* oldpath, const char* newpath)
|
|||
|
||||
int Process::sys$ftruncate(int fd, off_t length)
|
||||
{
|
||||
if (length < 0)
|
||||
return -EINVAL;
|
||||
auto* description = file_description(fd);
|
||||
if (!description)
|
||||
return -EBADF;
|
||||
// FIXME: Check that fd is writable, otherwise EINVAL.
|
||||
if (!description->is_writable())
|
||||
return -EBADF;
|
||||
return description->truncate(length);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue