From 80ea0fdcccada4edc03c233308577d3cdffa73fe Mon Sep 17 00:00:00 2001 From: Alexander Bluhm Date: Fri, 11 Aug 2017 19:53:03 +0000 Subject: Validate sockaddr from userland in central functions. This results in common checks for unix, inet, inet6 instead of partial checks here and there. Some checks are already done at a higher layer, but better be paranoid with user input. OK claudio@ millert@ --- sys/netinet/udp_usrreq.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'sys/netinet/udp_usrreq.c') diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 9700554b3ab..486b8d176e0 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.238 2017/06/26 09:32:32 mpi Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.239 2017/08/11 19:53:02 bluhm Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -960,26 +960,16 @@ udp_output(struct inpcb *inp, struct mbuf *m, struct mbuf *addr, } if (addr) { - sin = mtod(addr, struct sockaddr_in *); - - if (addr->m_len != sizeof(*sin)) { - error = EINVAL; - goto release; - } - if (sin->sin_family != AF_INET) { - error = EAFNOSUPPORT; + if ((error = in_nam2sin(addr, &sin))) goto release; - } if (sin->sin_port == 0) { error = EADDRNOTAVAIL; goto release; } - if (inp->inp_faddr.s_addr != INADDR_ANY) { error = EISCONN; goto release; } - error = in_pcbselsrc(&laddr, sin, inp); if (error) goto release; -- cgit v1.2.3