Fix lockfile flag checks

This commit is contained in:
Brian Almeida 2020-02-26 06:52:42 -05:00
parent 47078b8717
commit 910bbc398c
2 changed files with 4 additions and 2 deletions

View File

@ -212,9 +212,10 @@ out:
int fcntl_setlk(struct fd *fd, struct flock_ *flock, bool blocking) {
if (flock->type != F_RDLCK_ && flock->type != F_WRLCK_ && flock->type != F_UNLCK_)
return _EINVAL;
if (flock->type == F_RDLCK_ && !(fd_getflags(fd) & (O_RDONLY_|O_RDWR_)))
int fd_mode = fd_getflags(fd) & O_ACCMODE_;
if (flock->type == F_RDLCK_ && !(fd_mode == O_RDONLY_) && !(fd_mode == O_RDWR_))
return _EBADF;
if (flock->type == F_WRLCK_ && !(fd_getflags(fd) & (O_WRONLY_|O_RDWR_)))
if (flock->type == F_WRLCK_ && !(fd_mode == O_WRONLY_) && !(fd_mode == O_RDWR_))
return _EBADF;
struct inode_data *inode = fd->inode;

View File

@ -113,6 +113,7 @@ int mount_remove(struct mount *mount);
extern struct list mounts;
// open flags
#define O_ACCMODE_ 3
#define O_RDONLY_ 0
#define O_WRONLY_ (1 << 0)
#define O_RDWR_ (1 << 1)