Skip to content

Commit

Permalink
file: enforce file open() permissions in read() and write()
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 25, 2024
1 parent 388f135 commit f5e9ae8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ ssize_t readFile(Thread *t, uint64_t id, IODescriptor *iod, void *buffer, size_t
FileDescriptor *fd = (FileDescriptor *) iod->data;
if(!fd) return -EBADF;

if(!(iod->flags & O_RDONLY)) return -EPERM;

command->header.header.command = COMMAND_READ;
command->header.header.length = sizeof(RWCommand);
command->header.id = id;
Expand Down Expand Up @@ -121,6 +123,8 @@ ssize_t writeFile(Thread *t, uint64_t id, IODescriptor *iod, const void *buffer,
FileDescriptor *fd = (FileDescriptor *) iod->data;
if(!fd) return -EBADF;

if(!(iod->flags & O_WRONLY)) return -EPERM;

command->header.header.command = COMMAND_WRITE;
command->header.header.length = sizeof(RWCommand) + count;
command->header.id = id;
Expand Down

0 comments on commit f5e9ae8

Please sign in to comment.