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
This commit is contained in:
Mateusz Guzik 2012-07-09 05:39:31 +00:00
parent 6a9f8e0a06
commit 4fd85c4b5d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=238272

View File

@ -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)))) {
fdrop(fp, td);
return (EBADF);
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 (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