SonarCloud: Fix reported bugs

SonarCloud reported a few bugs, this commit should fix those reports.

Fix By: Brad House (@bradh352)
pull/576/head
Brad House 1 year ago
parent 3b10e571da
commit d35434d6bd
  1. 25
      src/lib/ares__addrinfo2hostent.c
  2. 2
      src/lib/ares_gethostbyaddr.c
  3. 2
      src/lib/ares_init.c
  4. 1
      src/lib/ares_process.c

@ -66,6 +66,15 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
if (ai == NULL || host == NULL)
return ARES_EBADQUERY;
/* Use the first node of the response as the family, since hostent can only
* represent one family. We assume getaddrinfo() returned a sorted list if
* the user requested AF_UNSPEC. */
if (family == AF_UNSPEC && ai->nodes)
family = ai->nodes->ai_family;
if (family != AF_INET && family != AF_INET6)
return ARES_EBADQUERY;
*host = ares_malloc(sizeof(**host));
if (!(*host))
{
@ -73,12 +82,6 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
}
memset(*host, 0, sizeof(**host));
/* Use the first node of the response as the family, since hostent can only
* represent one family. We assume getaddrinfo() returned a sorted list if
* the user requested AF_UNSPEC. */
if (family == AF_UNSPEC && ai->nodes)
family = ai->nodes->ai_family;
next = ai->nodes;
while (next)
{
@ -148,8 +151,12 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
}
(*host)->h_addrtype = family;
(*host)->h_length = (family == AF_INET)?
sizeof(struct in_addr):sizeof(struct ares_in6_addr);
if (family == AF_INET)
(*host)->h_length = sizeof(struct in_addr);
if (family == AF_INET6)
(*host)->h_length = sizeof(struct ares_in6_addr);
if (naddrs)
{
@ -172,7 +179,7 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
&(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
(size_t)(*host)->h_length);
}
else
if (family == AF_INET)
{
memcpy((*host)->h_addr_list[i],
&(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr),

@ -253,7 +253,7 @@ static ares_status_t file_lookup(struct ares_addr *addr, struct hostent **host)
}
else if (addr->family == AF_INET6)
{
if (memcmp((*host)->h_addr, &addr->addrV6,
if (memcmp((*host)->h_addr, addr->addrV6._S6_un._S6_u8,
sizeof(addr->addrV6)) == 0)
break;
}

@ -2120,6 +2120,8 @@ static ares_status_t config_sortlist(struct apattern **sortlist, size_t *nsort,
{
if (ipbufpfx[0])
{
if (q-str >= 16)
return ARES_EBADSTR;
memcpy(ipbuf, str, (size_t)(q-str));
ipbuf[q-str] = '\0';
if (ip_addr(ipbuf, q-str, &pat.mask.addr4) != 0)

@ -418,6 +418,7 @@ static void read_udp_packets_fd(ares_channel channel,
struct sockaddr_in sa4;
struct sockaddr_in6 sa6;
} from;
memset(&from, 0, sizeof(from));
#endif
/* To reduce event loop overhead, read and process as many

Loading…
Cancel
Save