ares_getaddrinfo using service of "0" should be allowed

As per #517 glibc allows a service/servname of "0" to be treated the
same as if NULL was provided.  Also, add a sanity check to ensure
the port number is in range instead of a blind cast.

Fixes: #517
Fix By: Brad House (@bradh352)
pull/520/head
bradh352 2 years ago
parent 38b30bc922
commit f95ca36cde
  1. 14
      src/lib/ares_getaddrinfo.c

@ -670,26 +670,32 @@ void ares_getaddrinfo(ares_channel channel,
{
if (hints->ai_flags & ARES_AI_NUMERICSERV)
{
port = (unsigned short)strtoul(service, NULL, 0);
if (!port)
unsigned long val;
errno = 0;
val = strtoul(service, NULL, 0);
if ((val == 0 && errno != 0) || val > 65535)
{
ares_free(alias_name);
callback(arg, ARES_ESERVICE, 0, NULL);
return;
}
port = (unsigned short)val;
}
else
{
port = lookup_service(service, 0);
if (!port)
{
port = (unsigned short)strtoul(service, NULL, 0);
if (!port)
unsigned long val;
errno = 0;
val = strtoul(service, NULL, 0);
if ((val == 0 && errno != 0) || val > 65535)
{
ares_free(alias_name);
callback(arg, ARES_ESERVICE, 0, NULL);
return;
}
port = (unsigned short)val;
}
}
}

Loading…
Cancel
Save