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 <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2018-02-05 21:00:15 +01:00
parent 34f031982f
commit 2f61f65601
1 changed files with 10 additions and 1 deletions

View File

@ -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);
}