https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2f61f65601b842af126c64cf02a556425afa1709

commit 2f61f65601b842af126c64cf02a556425afa1709
Author: Corinna Vinschen <cori...@vinschen.de>
Date:   Mon Feb 5 21:00:15 2018 +0100

    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 <cori...@vinschen.de>

Diff:
---
 winsup/cygwin/net.cc | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index b689012..cd43347 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);
 }

Reply via email to