libc: limit fcntl(F_SETFL) to file-status flags

This fixes unintended (and unpermitted) changes of O_ACCMODE bits.
This commit is contained in:
Christian Helmuth 2019-10-04 15:48:30 +02:00
parent e11addec7d
commit 732215a83f

View File

@ -1108,7 +1108,11 @@ int Libc::Vfs_plugin::fcntl(File_descriptor *fd, int cmd, long arg)
case F_SETFD: fd->cloexec = arg == FD_CLOEXEC; return 0;
case F_GETFL: return fd->flags;
case F_SETFL: fd->flags = arg; return 0;
case F_SETFL: {
/* only the specified flags may be changed */
long const mask = (O_NONBLOCK | O_APPEND | O_ASYNC | O_FSYNC);
fd->flags = (fd->flags & ~mask) | (arg & mask);
} return 0;
default:
break;