diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2002-08-23 22:21:45 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2002-08-23 22:21:45 +0000 |
commit | 9958388d0a4d2166f3f7b1acfaae96e99f8843b7 (patch) | |
tree | ab1d7cfaa82b05c8b9df1d55216c6a854b15a50c /sys/kern/uipc_syscalls.c | |
parent | b384e85014c8970773b255f11530482e7110ccfb (diff) |
Just like getvnode, make getsock FREF the file so that we can't get away
with not refing it.
Eyeballed by lurene@daemonkitty.net, fries@, nordin@ and fries@
Some additional cleanups by nordin@
Diffstat (limited to 'sys/kern/uipc_syscalls.c')
-rw-r--r-- | sys/kern/uipc_syscalls.c | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 4162dc34357..563903c2789 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_syscalls.c,v 1.52 2002/05/23 14:59:24 art Exp $ */ +/* $OpenBSD: uipc_syscalls.c,v 1.53 2002/08/23 22:21:44 art Exp $ */ /* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */ /* @@ -115,7 +115,6 @@ sys_bind(p, v, retval) if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); - FREF(fp); error = sockargs(&nam, (caddr_t)SCARG(uap, name), SCARG(uap, namelen), MT_SONAME); if (error == 0) { @@ -142,7 +141,6 @@ sys_listen(p, v, retval) if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); - FREF(fp); error = solisten((struct socket *)fp->f_data, SCARG(uap, backlog)); FRELE(fp); return (error); @@ -171,7 +169,6 @@ sys_accept(p, v, retval) return (error); if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); - FREF(fp); headfp = fp; s = splsoftnet(); head = (struct socket *)fp->f_data; @@ -283,9 +280,10 @@ sys_connect(p, v, retval) if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); so = (struct socket *)fp->f_data; - if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) + if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) { + FRELE(fp); return (EALREADY); - FREF(fp); + } error = sockargs(&nam, (caddr_t)SCARG(uap, name), SCARG(uap, namelen), MT_SONAME); if (error) @@ -480,6 +478,8 @@ sendit(p, s, mp, flags, retsize) struct iovec *ktriov = NULL; #endif + to = NULL; + if ((error = getsock(p->p_fd, s, &fp)) != 0) return (error); auio.uio_iov = mp->msg_iov; @@ -493,19 +493,17 @@ sendit(p, s, mp, flags, retsize) for (i = 0; i < mp->msg_iovlen; i++, iov++) { /* Don't allow sum > SSIZE_MAX */ if (iov->iov_len > SSIZE_MAX || - (auio.uio_resid += iov->iov_len) > SSIZE_MAX) - return (EINVAL); + (auio.uio_resid += iov->iov_len) > SSIZE_MAX) { + error = EINVAL; + goto bad; + } } - FREF(fp); if (mp->msg_name) { error = sockargs(&to, mp->msg_name, mp->msg_namelen, MT_SONAME); - if (error) { - FRELE(fp); - return (error); - } - } else - to = 0; + if (error) + goto bad; + } if (mp->msg_control) { if (mp->msg_controllen < sizeof(struct cmsghdr) #ifdef COMPAT_OLDSOCK @@ -666,7 +664,7 @@ recvit(p, s, mp, namelenp, retsize) register int i; size_t len; int error; - struct mbuf *from = 0, *control = 0; + struct mbuf *from = NULL, *control = NULL; #ifdef KTRACE struct iovec *ktriov = NULL; #endif @@ -684,10 +682,11 @@ recvit(p, s, mp, namelenp, retsize) for (i = 0; i < mp->msg_iovlen; i++, iov++) { /* Don't allow sum > SSIZE_MAX */ if (iov->iov_len > SSIZE_MAX || - (auio.uio_resid += iov->iov_len) > SSIZE_MAX) - return (EINVAL); + (auio.uio_resid += iov->iov_len) > SSIZE_MAX) { + error = EINVAL; + goto out; + } } - FREF(fp); #ifdef KTRACE if (KTRPOINT(p, KTR_GENIO)) { int iovlen = auio.uio_iovcnt * sizeof (struct iovec); @@ -820,7 +819,6 @@ sys_shutdown(p, v, retval) if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); - FREF(fp); error = soshutdown((struct socket *)fp->f_data, SCARG(uap, how)); FRELE(fp); return (error); @@ -846,9 +844,10 @@ sys_setsockopt(p, v, retval) if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); - if (SCARG(uap, valsize) > MCLBYTES) - return (EINVAL); - FREF(fp); + if (SCARG(uap, valsize) > MCLBYTES) { + error = EINVAL; + goto bad; + } if (SCARG(uap, val)) { m = m_get(M_WAIT, MT_SOOPTS); if (SCARG(uap, valsize) > MLEN) { @@ -900,7 +899,6 @@ sys_getsockopt(p, v, retval) if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); - FREF(fp); if (SCARG(uap, val)) { error = copyin((caddr_t)SCARG(uap, avalsize), (caddr_t)&valsize, sizeof (valsize)); @@ -971,7 +969,6 @@ sys_getsockname(p, v, retval) if ((error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) != 0) return (error); - FREF(fp); error = copyin((caddr_t)SCARG(uap, alen), (caddr_t)&len, sizeof (len)); if (error) goto bad; @@ -1017,9 +1014,10 @@ sys_getpeername(p, v, retval) if ((error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) != 0) return (error); so = (struct socket *)fp->f_data; - if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) + if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) { + FRELE(fp); return (ENOTCONN); - FREF(fp); + } error = copyin((caddr_t)SCARG(uap, alen), (caddr_t)&len, sizeof (len)); if (error) goto bad; @@ -1063,9 +1061,10 @@ sys_getpeereid(p, v, retval) if ((error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) != 0) return (error); so = (struct socket *)fp->f_data; - if (so->so_proto != pffindtype(AF_LOCAL, SOCK_STREAM)) + if (so->so_proto != pffindtype(AF_LOCAL, SOCK_STREAM)) { + FRELE(fp); return (EOPNOTSUPP); - FREF(fp); + } m = m_getclr(M_WAIT, MT_SONAME); if (m == NULL) { error = ENOBUFS; @@ -1146,5 +1145,7 @@ getsock(struct filedesc *fdp, int fdes, struct file **fpp) if (fp->f_type != DTYPE_SOCKET) return (ENOTSOCK); *fpp = fp; + FREF(fp); + return (0); } |