summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-02-02 16:05:59 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-02-02 16:05:59 +0000
commit1be6a40a464e4e44fb84b7d1fa048a217bbdeece (patch)
tree7e6c611fd09febf362436ee21ca66f3e3ab1fcaf /sys
parent5bdfd47e797e6f77a7f3809b3f0552d0218a364b (diff)
Be more consistent about using fd_getfile where it matters.
Diffstat (limited to 'sys')
-rw-r--r--sys/compat/hpux/hpux_tty.c6
-rw-r--r--sys/compat/ibcs2/ibcs2_fcntl.c7
-rw-r--r--sys/compat/linux/linux_file.c7
-rw-r--r--sys/compat/sunos/sunos_misc.c6
-rw-r--r--sys/compat/svr4/svr4_fcntl.c6
-rw-r--r--sys/compat/ultrix/ultrix_pathname.c6
-rw-r--r--sys/kern/sys_generic.c17
-rw-r--r--sys/kern/uipc_usrreq.c12
-rw-r--r--sys/miscfs/fdesc/fdesc_vnops.c8
-rw-r--r--sys/miscfs/portal/portal_vnops.c8
10 files changed, 44 insertions, 39 deletions
diff --git a/sys/compat/hpux/hpux_tty.c b/sys/compat/hpux/hpux_tty.c
index 4dd401ab892..e87ebb6298d 100644
--- a/sys/compat/hpux/hpux_tty.c
+++ b/sys/compat/hpux/hpux_tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hpux_tty.c,v 1.5 2001/10/26 12:03:27 art Exp $ */
+/* $OpenBSD: hpux_tty.c,v 1.6 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: hpux_tty.c,v 1.14 1997/04/01 19:59:05 scottr Exp $ */
/*
@@ -83,8 +83,8 @@ hpux_termio(fd, com, data, p)
int (*ioctlrout) __P((struct file *fp, u_long com,
caddr_t data, struct proc *p));
-
- fp = p->p_fd->fd_ofiles[fd];
+ if ((fp = fd_getfile(p->p_fd, fd)) == NULL)
+ return (EBADF);
ioctlrout = fp->f_ops->fo_ioctl;
switch (com) {
case HPUXTCGETATTR:
diff --git a/sys/compat/ibcs2/ibcs2_fcntl.c b/sys/compat/ibcs2/ibcs2_fcntl.c
index 3352d62a7fe..dcdb6d1bdad 100644
--- a/sys/compat/ibcs2/ibcs2_fcntl.c
+++ b/sys/compat/ibcs2/ibcs2_fcntl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ibcs2_fcntl.c,v 1.6 2000/04/21 15:50:22 millert Exp $ */
+/* $OpenBSD: ibcs2_fcntl.c,v 1.7 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: ibcs2_fcntl.c,v 1.6 1996/05/03 17:05:20 christos Exp $ */
/*
@@ -185,9 +185,10 @@ ibcs2_sys_open(p, v, retval)
if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
struct filedesc *fdp = p->p_fd;
- struct file *fp = fdp->fd_ofiles[*retval];
+ struct file *fp;
- /* ignore any error, just give it a try */
+ if ((fp = fd_getfile(fdp, *retval)) == NULL)
+ return EBADF;
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
}
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index c7e1ba769cc..9b2e3b49e8e 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_file.c,v 1.18 2001/10/26 12:03:27 art Exp $ */
+/* $OpenBSD: linux_file.c,v 1.19 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: linux_file.c,v 1.15 1996/05/20 01:59:09 fvdl Exp $ */
/*
@@ -192,9 +192,10 @@ linux_sys_open(p, v, retval)
*/
if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
struct filedesc *fdp = p->p_fd;
- struct file *fp = fdp->fd_ofiles[*retval];
+ struct file *fp;
- /* ignore any error, just give it a try */
+ if ((fp = fd_getfile(fdp, *retval)) == NULL)
+ return (EBADF);
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p);
}
diff --git a/sys/compat/sunos/sunos_misc.c b/sys/compat/sunos/sunos_misc.c
index 6e92dd5c68b..685803ead25 100644
--- a/sys/compat/sunos/sunos_misc.c
+++ b/sys/compat/sunos/sunos_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sunos_misc.c,v 1.30 2001/11/06 19:53:17 miod Exp $ */
+/* $OpenBSD: sunos_misc.c,v 1.31 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: sunos_misc.c,v 1.65 1996/04/22 01:44:31 christos Exp $ */
/*
@@ -685,8 +685,10 @@ sunos_sys_open(p, v, retval)
if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
struct filedesc *fdp = p->p_fd;
- struct file *fp = fdp->fd_ofiles[*retval];
+ struct file *fp;
+ if ((fp = fd_getfile(fdp, *retval)) == NULL)
+ return (EBADF);
/* ignore any error, just give it a try */
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
diff --git a/sys/compat/svr4/svr4_fcntl.c b/sys/compat/svr4/svr4_fcntl.c
index a859b7af903..189e3744886 100644
--- a/sys/compat/svr4/svr4_fcntl.c
+++ b/sys/compat/svr4/svr4_fcntl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_fcntl.c,v 1.19 2001/10/26 12:03:27 art Exp $ */
+/* $OpenBSD: svr4_fcntl.c,v 1.20 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: svr4_fcntl.c,v 1.14 1995/10/14 20:24:24 christos Exp $ */
/*
@@ -334,8 +334,10 @@ svr4_sys_open(p, v, retval)
if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) &&
!(p->p_flag & P_CONTROLT)) {
struct filedesc *fdp = p->p_fd;
- struct file *fp = fdp->fd_ofiles[*retval];
+ struct file *fp;
+ if ((fp = fd_getfile(fdp, *retval)) == NULL)
+ return (EBADF);
/* ignore any error, just give it a try */
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p);
diff --git a/sys/compat/ultrix/ultrix_pathname.c b/sys/compat/ultrix/ultrix_pathname.c
index 80ea178d427..b4e55576064 100644
--- a/sys/compat/ultrix/ultrix_pathname.c
+++ b/sys/compat/ultrix/ultrix_pathname.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ultrix_pathname.c,v 1.4 2000/04/21 15:50:21 millert Exp $ */
+/* $OpenBSD: ultrix_pathname.c,v 1.5 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: ultrix_pathname.c,v 1.2 1996/04/07 17:23:07 jonathan Exp $ */
/*
@@ -185,8 +185,10 @@ ultrix_sys_open(p, v, retval)
if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
struct filedesc *fdp = p->p_fd;
- struct file *fp = fdp->fd_ofiles[*retval];
+ struct file *fp;
+ if ((fd = fd_getfile(fdp, *retval)) == NULL)
+ return (EBADF);
/* ignore any error, just give it a try */
if (fp->f_type == DTYPE_VNODE)
(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index ea62a488a66..575e4fc58c0 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_generic.c,v 1.31 2001/11/14 19:47:07 deraadt Exp $ */
+/* $OpenBSD: sys_generic.c,v 1.32 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
@@ -787,8 +787,7 @@ selscan(p, ibits, obits, nfd, retval)
bits = pibits->fds_bits[i/NFDBITS];
while ((j = ffs(bits)) && (fd = i + --j) < nfd) {
bits &= ~(1 << j);
- fp = fdp->fd_ofiles[fd];
- if (fp == NULL)
+ if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
if ((*fp->f_ops->fo_select)(fp, flag[msk], p)) {
FD_SET(fd, pobits);
@@ -884,19 +883,11 @@ pollscan(p, pl, nfd, retval)
*/
for (i = 0; i < nfd; i++) {
/* Check the file descriptor. */
- if (pl[i].fd < 0)
- continue;
- if (pl[i].fd >= fdp->fd_nfiles) {
- pl[i].revents = POLLNVAL;
- n++;
- continue;
- } else if (pl[i].fd < 0) {
+ if (pl[i].fd < 0) {
pl[i].revents = 0;
continue;
}
-
- fp = fdp->fd_ofiles[pl[i].fd];
- if (fp == NULL) {
+ if ((fp = fd_getfile(fdp, pl[i].fd)) == NULL) {
pl[i].revents = POLLNVAL;
n++;
continue;
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 46b675b3c96..0d04d9a80d5 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.15 2001/10/26 12:03:27 art Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.16 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -750,11 +750,12 @@ unp_internalize(control, p)
oldfds = (cm->cmsg_len - sizeof (*cm)) / sizeof (int);
ip = (int *)(cm + 1);
for (i = 0; i < oldfds; i++) {
+ struct file *fp;
fd = *ip++;
- if (fd_getfile(fdp, fd) == NULL)
+ if ((fp = fd_getfile(fdp, fd)) == NULL)
return (EBADF);
- if (fdp->fd_ofiles[fd]->f_count == LONG_MAX-2 ||
- fdp->fd_ofiles[fd]->f_msgcount == LONG_MAX-2)
+ if (fp->f_count == LONG_MAX-2 ||
+ fp->f_msgcount == LONG_MAX-2)
return (EDEADLK);
}
ip = (int *)(cm + 1);
@@ -766,7 +767,8 @@ unp_internalize(control, p)
for (i = 0; i < oldfds; i++) {
bcopy(ip, &fd, sizeof fd);
ip++;
- fp = fdp->fd_ofiles[fd];
+ fp = fd_getfile(fdp, fd);
+ /* XXX - are ew really sure that this will never fail? */
bcopy(&fp, rp, sizeof fp);
rp++;
fp->f_count++;
diff --git a/sys/miscfs/fdesc/fdesc_vnops.c b/sys/miscfs/fdesc/fdesc_vnops.c
index b5c22156ecf..632fc28bd74 100644
--- a/sys/miscfs/fdesc/fdesc_vnops.c
+++ b/sys/miscfs/fdesc/fdesc_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdesc_vnops.c,v 1.27 2001/12/19 08:58:06 art Exp $ */
+/* $OpenBSD: fdesc_vnops.c,v 1.28 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: fdesc_vnops.c,v 1.32 1996/04/11 11:24:29 mrg Exp $ */
/*
@@ -352,7 +352,7 @@ fdesc_lookup(v)
goto bad;
}
- if (fd >= nfiles || p->p_fd->fd_ofiles[fd] == NULL) {
+ if (fd_getfile(p->p_fd, fd) == NULL) {
error = EBADF;
goto bad;
}
@@ -658,7 +658,7 @@ fdesc_readdir(v)
case FD_STDERR:
if ((ft->ft_fileno - FD_STDIN) >= fdp->fd_nfiles)
continue;
- if (fdp->fd_ofiles[ft->ft_fileno - FD_STDIN] == NULL)
+ if (fd_getfile(fdp, ft->ft_fileno - FD_STDIN) == NULL)
continue;
break;
}
@@ -685,7 +685,7 @@ fdesc_readdir(v)
break;
default:
- if (fdp->fd_ofiles[i - 2] == NULL)
+ if (fd_getfile(fdp, i - 2) == NULL)
continue;
d.d_fileno = i - 2 + FD_STDIN;
d.d_namlen = sprintf(d.d_name, "%d", i - 2);
diff --git a/sys/miscfs/portal/portal_vnops.c b/sys/miscfs/portal/portal_vnops.c
index fd4489984e1..4bc2aa8a4dc 100644
--- a/sys/miscfs/portal/portal_vnops.c
+++ b/sys/miscfs/portal/portal_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: portal_vnops.c,v 1.10 2001/12/04 22:44:32 art Exp $ */
+/* $OpenBSD: portal_vnops.c,v 1.11 2002/02/02 16:05:58 art Exp $ */
/* $NetBSD: portal_vnops.c,v 1.17 1996/02/13 13:12:57 mycroft Exp $ */
/*
@@ -475,7 +475,11 @@ portal_open(v)
* Check that the mode the file is being opened for is a subset
* of the mode of the existing descriptor.
*/
- fp = p->p_fd->fd_ofiles[fd];
+ if ((fp = fd_getfile(p->p_fd, fd)) == NULL) {
+ portal_closefd(p, fd);
+ error = EBADF;
+ goto bad;
+ }
if (((ap->a_mode & (FREAD|FWRITE)) | fp->f_flag) != fp->f_flag) {
portal_closefd(p, fd);
error = EACCES;