Add sanity check for return of sotoinpcb() and intotcpcb()
[unix-history] / sys / netinet / tcp_usrreq.c
index e52f02d..0ddf870 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *     from: @(#)tcp_usrreq.c  7.15 (Berkeley) 6/28/90
  * SUCH DAMAGE.
  *
  *     from: @(#)tcp_usrreq.c  7.15 (Berkeley) 6/28/90
- *     $Id$
+ *     $Id: tcp_usrreq.c,v 1.5 1994/01/24 05:12:36 davidg Exp $
  */
 
 #include "param.h"
  */
 
 #include "param.h"
 #include "tcp_timer.h"
 #include "tcp_var.h"
 #include "tcpip.h"
 #include "tcp_timer.h"
 #include "tcp_var.h"
 #include "tcpip.h"
+#ifdef TCPDEBUG
 #include "tcp_debug.h"
 #include "tcp_debug.h"
+#endif
 
 /*
  * TCP protocol interface to socket abstraction.
  */
 extern char *tcpstates[];
 
 /*
  * TCP protocol interface to socket abstraction.
  */
 extern char *tcpstates[];
-struct tcpcb *tcp_newtcpcb();
 
 /*
  * Process a TCP user request for TCP tb.  If this is a send request
 
 /*
  * Process a TCP user request for TCP tb.  If this is a send request
@@ -72,13 +73,15 @@ struct      tcpcb *tcp_newtcpcb();
  * (called from the software clock routine), then timertype tells which timer.
  */
 /*ARGSUSED*/
  * (called from the software clock routine), then timertype tells which timer.
  */
 /*ARGSUSED*/
-tcp_usrreq(so, req, m, nam, control)
+int
+tcp_usrreq(so, req, m, nam, control, dummy)
        struct socket *so;
        int req;
        struct mbuf *m, *nam, *control;
        struct socket *so;
        int req;
        struct mbuf *m, *nam, *control;
+       struct mbuf *dummy;
 {
        register struct inpcb *inp;
 {
        register struct inpcb *inp;
-       register struct tcpcb *tp;
+       register struct tcpcb *tp = 0;
        int s;
        int error = 0;
        int ostate;
        int s;
        int error = 0;
        int ostate;
@@ -331,12 +334,15 @@ tcp_usrreq(so, req, m, nam, control)
        default:
                panic("tcp_usrreq");
        }
        default:
                panic("tcp_usrreq");
        }
+#ifdef TCPDEBUG
        if (tp && (so->so_options & SO_DEBUG))
                tcp_trace(TA_USER, ostate, tp, (struct tcpiphdr *)0, req);
        if (tp && (so->so_options & SO_DEBUG))
                tcp_trace(TA_USER, ostate, tp, (struct tcpiphdr *)0, req);
+#endif
        splx(s);
        return (error);
 }
 
        splx(s);
        return (error);
 }
 
+int
 tcp_ctloutput(op, so, level, optname, mp)
        int op;
        struct socket *so;
 tcp_ctloutput(op, so, level, optname, mp)
        int op;
        struct socket *so;
@@ -345,12 +351,15 @@ tcp_ctloutput(op, so, level, optname, mp)
 {
        int error = 0;
        struct inpcb *inp = sotoinpcb(so);
 {
        int error = 0;
        struct inpcb *inp = sotoinpcb(so);
-       register struct tcpcb *tp = intotcpcb(inp);
+       register struct tcpcb *tp;
        register struct mbuf *m;
 
        if (level != IPPROTO_TCP)
                return (ip_ctloutput(op, so, level, optname, mp));
 
        register struct mbuf *m;
 
        if (level != IPPROTO_TCP)
                return (ip_ctloutput(op, so, level, optname, mp));
 
+       if (!inp || !(tp = intotcpcb(inp)))
+               return (EINVAL);
+
        switch (op) {
 
        case PRCO_SETOPT:
        switch (op) {
 
        case PRCO_SETOPT:
@@ -395,19 +404,12 @@ tcp_ctloutput(op, so, level, optname, mp)
        return (error);
 }
 
        return (error);
 }
 
-#ifdef TCP_SMALLSPACE
-u_long tcp_sendspace = 1024*4;
-u_long tcp_recvspace = 1024*4;
-#else
-u_long tcp_sendspace = 1024*16;
-u_long tcp_recvspace = 1024*16;
-#endif /* TCP_SMALLSPACE */
-
 /*
  * Attach TCP protocol to socket, allocating
  * internet protocol control block, tcp control block,
  * bufer space, and entering LISTEN state if to accept connections.
  */
 /*
  * Attach TCP protocol to socket, allocating
  * internet protocol control block, tcp control block,
  * bufer space, and entering LISTEN state if to accept connections.
  */
+int
 tcp_attach(so)
        struct socket *so;
 {
 tcp_attach(so)
        struct socket *so;
 {