diff options
author | mjg <mjg@FreeBSD.org> | 2012-07-09 05:39:31 +0000 |
---|---|---|
committer | mjg <mjg@FreeBSD.org> | 2012-07-09 05:39:31 +0000 |
commit | 24d9f5c7d649df6299434ef62e52d3f53708225d (patch) | |
tree | b1fa0038ad096a82406fad6b40840045449ae0fc /sys/kern | |
parent | a596d3e5b38804358cd22493f964b64c36567719 (diff) | |
download | FreeBSD-src-24d9f5c7d649df6299434ef62e52d3f53708225d.zip FreeBSD-src-24d9f5c7d649df6299434ef62e52d3f53708225d.tar.gz |
Follow-up commit to r238220:
Pass only FEXEC (instead of FREAD|FEXEC) in fgetvp_exec. _fget has to check for
!FWRITE anyway and may as well know about FREAD.
Make _fget code a bit more readable by converting permission checking from if()
to switch(). Assert that correct permission flags are passed.
In collaboration with: kib
Approved by: trasz (mentor)
MFC after: 6 days
X-MFC: with r238220
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_descrip.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index a4b7580..f8e3f3d 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -2275,8 +2275,8 @@ _fget(struct thread *td, int fd, struct file **fpp, int flags, struct file *fp; #ifdef CAPABILITIES struct file *fp_fromcap; - int error; #endif + int error; *fpp = NULL; if (td == NULL || (fdp = td->td_proc->p_fd) == NULL) @@ -2315,7 +2315,7 @@ _fget(struct thread *td, int fd, struct file **fpp, int flags, else error = cap_funwrap_mmap(fp, needrights, maxprotp, &fp_fromcap); - if (error) { + if (error != 0) { fdrop(fp, td); return (error); } @@ -2341,13 +2341,29 @@ _fget(struct thread *td, int fd, struct file **fpp, int flags, /* * FREAD and FWRITE failure return EBADF as per POSIX. */ - if ((flags == FREAD && (fp->f_flag & FREAD) == 0) || - (flags == FWRITE && (fp->f_flag & FWRITE) == 0) || - (flags == (FREAD | FEXEC) && - (((fp->f_flag & flags) == 0) || ((fp->f_flag & FWRITE) != 0)))) { + error = 0; + switch (flags) { + case FREAD: + case FWRITE: + if ((fp->f_flag & flags) == 0) + error = EBADF; + break; + case FEXEC: + if ((fp->f_flag & (FREAD | FEXEC)) == 0 || + ((fp->f_flag & FWRITE) != 0)) + error = EBADF; + break; + case 0: + break; + default: + KASSERT(0, ("wrong flags")); + } + + if (error != 0) { fdrop(fp, td); - return (EBADF); + return (error); } + *fpp = fp; return (0); } @@ -2448,7 +2464,7 @@ int fgetvp_exec(struct thread *td, int fd, cap_rights_t rights, struct vnode **vpp) { - return (_fgetvp(td, fd, FREAD | FEXEC, rights, NULL, vpp)); + return (_fgetvp(td, fd, FEXEC, rights, NULL, vpp)); } #ifdef notyet |