mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-11 05:12:05 +00:00
Libc: check O_DIRECTORY flag at 'open' and 'read'
Return an error when opening a file with 'O_DIRECTORY'. Return an error when reading directories. Ref #2533
This commit is contained in:
parent
2b006dbaac
commit
2bbb183a18
@ -172,10 +172,12 @@ Libc::File_descriptor *Libc::Vfs_plugin::open(char const *path, int flags,
|
||||
if (_root_dir.directory(path)) {
|
||||
|
||||
if (((flags & O_ACCMODE) != O_RDONLY)) {
|
||||
errno = EINVAL;
|
||||
errno = EISDIR;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
flags |= O_DIRECTORY;
|
||||
|
||||
Vfs::Vfs_handle *handle = 0;
|
||||
|
||||
typedef Vfs::Directory_service::Opendir_result Opendir_result;
|
||||
@ -208,6 +210,11 @@ Libc::File_descriptor *Libc::Vfs_plugin::open(char const *path, int flags,
|
||||
return fd;
|
||||
}
|
||||
|
||||
if (flags & O_DIRECTORY) {
|
||||
errno = ENOTDIR;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
typedef Vfs::Directory_service::Open_result Result;
|
||||
|
||||
Vfs::Vfs_handle *handle = 0;
|
||||
@ -452,6 +459,9 @@ ssize_t Libc::Vfs_plugin::read(Libc::File_descriptor *fd, void *buf,
|
||||
|
||||
Vfs::Vfs_handle *handle = vfs_handle(fd);
|
||||
|
||||
if (fd->flags & O_DIRECTORY)
|
||||
return Errno(EISDIR);
|
||||
|
||||
if (fd->flags & O_NONBLOCK && !Libc::read_ready(fd))
|
||||
return Errno(EAGAIN);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user