1
Fork 0
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:
Andreas Kling 2020-01-07 14:42:56 +01:00
parent bb9db9d430
commit 6a4b376021
2 changed files with 24 additions and 1 deletions

View file

@ -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);
}