Before dereferencing intotw() check for NULL, the same way as it is

done for in_pcb (see r157474).

MFC after:	1 week
This commit is contained in:
trociny 2011-11-06 09:29:52 +00:00
parent a22bc64df7
commit ddbde914da

View File

@ -187,6 +187,7 @@ in6_pcbbind(register struct inpcb *inp, struct sockaddr *nam,
} }
if (lport) { if (lport) {
struct inpcb *t; struct inpcb *t;
struct tcptw *tw;
/* GROSS */ /* GROSS */
if (ntohs(lport) <= V_ipport_reservedhigh && if (ntohs(lport) <= V_ipport_reservedhigh &&
@ -233,10 +234,21 @@ in6_pcbbind(register struct inpcb *inp, struct sockaddr *nam,
} }
t = in6_pcblookup_local(pcbinfo, &sin6->sin6_addr, t = in6_pcblookup_local(pcbinfo, &sin6->sin6_addr,
lport, lookupflags, cred); lport, lookupflags, cred);
if (t && (reuseport & ((t->inp_flags & INP_TIMEWAIT) ? if (t && (t->inp_flags & INP_TIMEWAIT)) {
intotw(t)->tw_so_options : /*
t->inp_socket->so_options)) == 0) * XXXRW: If an incpb has had its timewait
* state recycled, we treat the address as
* being in use (for now). This is better
* than a panic, but not desirable.
*/
tw = intotw(t);
if (tw == NULL ||
(reuseport & tw->tw_so_options) == 0)
return (EADDRINUSE);
} else if (t && (reuseport & t->inp_socket->so_options)
== 0) {
return (EADDRINUSE); return (EADDRINUSE);
}
#ifdef INET #ifdef INET
if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0 && if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0 &&
IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
@ -246,9 +258,11 @@ in6_pcbbind(register struct inpcb *inp, struct sockaddr *nam,
t = in_pcblookup_local(pcbinfo, sin.sin_addr, t = in_pcblookup_local(pcbinfo, sin.sin_addr,
lport, lookupflags, cred); lport, lookupflags, cred);
if (t && t->inp_flags & INP_TIMEWAIT) { if (t && t->inp_flags & INP_TIMEWAIT) {
if ((reuseport & tw = intotw(t);
intotw(t)->tw_so_options) == 0 && if (tw == NULL)
(ntohl(t->inp_laddr.s_addr) != return (EADDRINUSE);
if ((reuseport & tw->tw_so_options) == 0
&& (ntohl(t->inp_laddr.s_addr) !=
INADDR_ANY || ((inp->inp_vflag & INADDR_ANY || ((inp->inp_vflag &
INP_IPV6PROTO) == INP_IPV6PROTO) ==
(t->inp_vflag & INP_IPV6PROTO)))) (t->inp_vflag & INP_IPV6PROTO))))