From 2f61f65601b842af126c64cf02a556425afa1709 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 5 Feb 2018 21:00:15 +0100 Subject: Cygwin: bindresvport: check correctness of address family Assuming the address parameter is non-NULL, the test in cygwin_bindresvport_sa only tests if the address family is supported at all, which is insufficient. Check if the incoming address family matches the socket address family and for being AF_INET in cygwin_bindresvport since the latter doesn't support any other family. Signed-off-by: Corinna Vinschen --- winsup/cygwin/net.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'winsup/cygwin/net.cc') diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index b6890121a..cd4334738 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -2482,6 +2482,11 @@ cygwin_bindresvport_sa (int fd, struct sockaddr *sa) memset (&sst, 0, sizeof sst); sa->sa_family = fh->get_addr_family (); } + else if (sa->sa_family != fh->get_addr_family ()) + { + set_errno (EPFNOSUPPORT); + __leave; + } switch (sa->sa_family) { @@ -2529,10 +2534,14 @@ cygwin_bindresvport_sa (int fd, struct sockaddr *sa) return ret; } - extern "C" int cygwin_bindresvport (int fd, struct sockaddr_in *sin) { + if (sin && sin->sin_family != AF_INET) + { + set_errno (EAFNOSUPPORT); + return -1; + } return cygwin_bindresvport_sa (fd, (struct sockaddr *) sin); } -- cgit v1.2.3