Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/uipc_socket.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/kern/uipc_socket.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.26 retrieving revision 1.32 diff -u -p -r1.26 -r1.32 --- src/sys/kern/uipc_socket.c 1997/01/11 05:15:01 1.26 +++ src/sys/kern/uipc_socket.c 1998/03/01 02:22:34 1.32 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.26 1997/01/11 05:15:01 thorpej Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.32 1998/03/01 02:22:34 fvdl Exp $ */ /* * Copyright (c) 1982, 1986, 1988, 1990, 1993 @@ -32,7 +32,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 + * @(#)uipc_socket.c 8.6 (Berkeley) 5/2/95 */ #include @@ -79,6 +79,8 @@ socreate(dom, aso, type, proto) return (EPROTOTYPE); MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT); bzero((caddr_t)so, sizeof(*so)); + TAILQ_INIT(&so->so_q0); + TAILQ_INIT(&so->so_q); so->so_type = type; so->so_proto = prp; error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, @@ -127,7 +129,7 @@ solisten(so, backlog) splx(s); return (error); } - if (so->so_q == 0) + if (so->so_q.tqh_first == NULL) so->so_options |= SO_ACCEPTCONN; if (backlog < 0) backlog = 0; @@ -166,10 +168,10 @@ soclose(so) int error = 0; if (so->so_options & SO_ACCEPTCONN) { - while (so->so_q0) - (void) soabort(so->so_q0); - while (so->so_q) - (void) soabort(so->so_q); + while (so->so_q0.tqh_first) + (void) soabort(so->so_q0.tqh_first); + while (so->so_q.tqh_first) + (void) soabort(so->so_q.tqh_first); } if (so->so_pcb == 0) goto discard; @@ -186,7 +188,7 @@ soclose(so) while (so->so_state & SS_ISCONNECTED) { error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH, netcls, - so->so_linger); + so->so_linger * hz); if (error) break; } @@ -350,8 +352,10 @@ sosend(so, addr, uio, top, control, flag * of space and resid. On the other hand, a negative resid * causes us to loop sending 0-length segments to the protocol. */ - if (resid < 0) - return (EINVAL); + if (resid < 0) { + error = EINVAL; + goto out; + } dontroute = (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 && (so->so_proto->pr_flags & PR_ATOMIC); @@ -887,30 +891,53 @@ sosetopt(so, level, optname, m0) case SO_RCVBUF: case SO_SNDLOWAT: case SO_RCVLOWAT: + { + int optval; + if (m == NULL || m->m_len < sizeof (int)) { error = EINVAL; goto bad; } + + /* + * Values < 1 make no sense for any of these + * options, so disallow them. + */ + optval = *mtod(m, int *); + if (optval < 1) { + error = EINVAL; + goto bad; + } + switch (optname) { case SO_SNDBUF: case SO_RCVBUF: if (sbreserve(optname == SO_SNDBUF ? &so->so_snd : &so->so_rcv, - (u_long) *mtod(m, int *)) == 0) { + (u_long) optval) == 0) { error = ENOBUFS; goto bad; } break; + /* + * Make sure the low-water is never greater than + * the high-water. + */ case SO_SNDLOWAT: - so->so_snd.sb_lowat = *mtod(m, int *); + so->so_snd.sb_lowat = + (optval > so->so_snd.sb_hiwat) ? + so->so_snd.sb_hiwat : optval; break; case SO_RCVLOWAT: - so->so_rcv.sb_lowat = *mtod(m, int *); + so->so_rcv.sb_lowat = + (optval > so->so_rcv.sb_hiwat) ? + so->so_rcv.sb_hiwat : optval; break; } break; + } case SO_SNDTIMEO: case SO_RCVTIMEO: @@ -1030,7 +1057,7 @@ sogetopt(so, level, optname, mp) m->m_len = sizeof(struct timeval); mtod(m, struct timeval *)->tv_sec = val / hz; mtod(m, struct timeval *)->tv_usec = - (val % hz) / tick; + (val % hz) * tick; break; }