mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:37:34 +00:00
Kernel: read() and write() should fail with EBADF for wrong mode fd's
It was previously possible to write to read-only file descriptors, and read from write-only file descriptors. All FileDescription objects now start out non-readable + non-writable, and whoever is creating them has to "manually" enable reading/writing by calling set_readable() and/or set_writable() on them.
This commit is contained in:
parent
2da3edb3d0
commit
0a1865ebc6
2 changed files with 39 additions and 0 deletions
|
@ -25,6 +25,26 @@ public:
|
|||
static NonnullRefPtr<FileDescription> create(File&);
|
||||
~FileDescription();
|
||||
|
||||
bool is_readable() const { return m_readable; }
|
||||
bool is_writable() const { return m_writable; }
|
||||
|
||||
void set_readable(bool b) { m_readable = b; }
|
||||
void set_writable(bool b) { m_writable = b; }
|
||||
|
||||
void set_rw_mode(int options)
|
||||
{
|
||||
if (options & O_WRONLY) {
|
||||
set_readable(false);
|
||||
set_writable(true);
|
||||
} else if (options & O_RDWR) {
|
||||
set_readable(true);
|
||||
set_writable(true);
|
||||
} else {
|
||||
set_readable(true);
|
||||
set_writable(false);
|
||||
}
|
||||
}
|
||||
|
||||
int close();
|
||||
|
||||
off_t seek(off_t, int whence);
|
||||
|
@ -111,6 +131,8 @@ private:
|
|||
|
||||
u32 m_file_flags { 0 };
|
||||
|
||||
bool m_readable { false };
|
||||
bool m_writable { false };
|
||||
bool m_is_blocking { true };
|
||||
bool m_is_directory { false };
|
||||
bool m_should_append { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue