kernel: Disallow write-related flags when opening a directory, not only when the directory flag is set
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Also return EISDIR instead of EINVAL as that is what Dr. POSIX mandates.
This commit is contained in:
parent
1035b91a3d
commit
64d0f30bd9
@ -23,11 +23,6 @@ Result<u64> sys_openat(Registers*, SyscallArgs args)
|
||||
// Caller did not pass either O_RDONLY, O_WRONLY or O_RDWR
|
||||
if ((flags & O_RDWR) == 0) { return err(EINVAL); }
|
||||
|
||||
if (flags & O_DIRECTORY)
|
||||
{
|
||||
if ((flags & O_WRONLY) || (flags & O_CREAT)) return err(EINVAL);
|
||||
}
|
||||
|
||||
if (flags & O_TMPFILE)
|
||||
{
|
||||
if (!(flags & O_WRONLY)) return err(EINVAL);
|
||||
@ -66,6 +61,11 @@ Result<u64> sys_openat(Registers*, SyscallArgs args)
|
||||
|
||||
if (inode->type() != VFS::InodeType::Directory && (flags & O_DIRECTORY)) return err(ENOTDIR);
|
||||
|
||||
if (inode->type() == VFS::InodeType::Directory)
|
||||
{
|
||||
if ((flags & O_WRONLY) || (flags & O_CREAT)) return err(EISDIR);
|
||||
}
|
||||
|
||||
if ((flags & O_WRONLY) && (flags & O_TRUNC)) inode->truncate(0);
|
||||
|
||||
int fd = TRY(current->allocate_fd(0));
|
||||
|
Loading…
Reference in New Issue
Block a user