Coverage code annotations for identification of desirable paths that need testing (#775)

Add code annotations for ignoring specific code paths for coverage
calculations. The primary purpose of this is to make it easy to see the
code paths that we could (and probably should) write test cases for, as
these would have the most impact on delivery of a stable product.

The annotations used are:
`LCOV_EXCL_LINE: <designation>`, `LCOV_EXCL_START: <designation>`,
`LCOV_EXCL_STOP`

Unfortunately `LCOV_EXCL_BR_LINE` does not appear to be supported by
coveralls as it would have been a more elegant solution over START/STOP.

We specifically include the `<designation>` not just for future
reference but because it makes it easy to identify in case we want to
address these conditions in a different way in the future.

The main areas designated for exclusion are:
1. `OutOfMemory` - these are hard to test cases, and on modern systems,
are likely to never occur due to optimistic memory allocations, which
can then later cause the kernel to terminate your application due to
memory not actually being available. c-ares does have *some* testing
framework for this, if we wish to expand in the future, we can easily
use sed to get rid of of these annotations.
2. `DefensiveCoding` - these are impossible to reach paths at the point
in time the code was written. They are there for defensive coding in
case code is refactored in the future to prevent unexpected behavior.
3. `UntestablePath` - these are code paths that aren't possible to test,
such as failure of a system call.
4. `FallbackCode` - This is an entire set of code that is untestable
because its not able to simulate a failure of the primary path.

This PR also does add some actual coverage in the test cases where it is
easy to do.

Fix By: Brad House (@bradh352)
pull/786/head
Brad House 5 months ago committed by GitHub
parent 80a685e198
commit c0d41d08ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 30
      src/lib/ares__addrinfo2hostent.c
  2. 18
      src/lib/ares__addrinfo_localhost.c
  3. 82
      src/lib/ares__buf.c
  4. 2
      src/lib/ares__close_sockets.c
  5. 86
      src/lib/ares__hosts_file.c
  6. 12
      src/lib/ares__htable_asvp.c
  7. 6
      src/lib/ares__htable_szvp.c
  8. 8
      src/lib/ares__htable_vpvp.c
  9. 31
      src/lib/ares__iface_ips.c
  10. 10
      src/lib/ares__llist.c
  11. 22
      src/lib/ares__parse_into_addrinfo.c
  12. 10
      src/lib/ares__slist.c
  13. 18
      src/lib/ares__socket.c
  14. 16
      src/lib/ares__threads.c
  15. 2
      src/lib/ares__timeval.c
  16. 4
      src/lib/ares_cancel.c
  17. 2
      src/lib/ares_destroy.c
  18. 70
      src/lib/ares_dns_name.c
  19. 8
      src/lib/ares_dns_parse.c
  20. 12
      src/lib/ares_dns_record.c
  21. 134
      src/lib/ares_dns_write.c
  22. 14
      src/lib/ares_event_configchg.c
  23. 20
      src/lib/ares_event_epoll.c
  24. 6
      src/lib/ares_event_poll.c
  25. 4
      src/lib/ares_event_select.c
  26. 42
      src/lib/ares_event_thread.c
  27. 14
      src/lib/ares_event_wake_pipe.c
  28. 20
      src/lib/ares_expand_name.c
  29. 2
      src/lib/ares_expand_string.c
  30. 20
      src/lib/ares_getaddrinfo.c
  31. 8
      src/lib/ares_gethostbyaddr.c
  32. 10
      src/lib/ares_gethostbyname.c
  33. 34
      src/lib/ares_init.c
  34. 20
      src/lib/ares_options.c
  35. 2
      src/lib/ares_parse_a_reply.c
  36. 2
      src/lib/ares_parse_aaaa_reply.c
  37. 20
      src/lib/ares_parse_caa_reply.c
  38. 12
      src/lib/ares_parse_mx_reply.c
  39. 24
      src/lib/ares_parse_naptr_reply.c
  40. 26
      src/lib/ares_parse_ns_reply.c
  41. 16
      src/lib/ares_parse_ptr_reply.c
  42. 16
      src/lib/ares_parse_soa_reply.c
  43. 12
      src/lib/ares_parse_srv_reply.c
  44. 12
      src/lib/ares_parse_txt_reply.c
  45. 8
      src/lib/ares_parse_uri_reply.c
  46. 5
      src/lib/ares_private.h
  47. 32
      src/lib/ares_process.c
  48. 54
      src/lib/ares_qcache.c
  49. 12
      src/lib/ares_query.c
  50. 32
      src/lib/ares_rand.c
  51. 34
      src/lib/ares_search.c
  52. 12
      src/lib/ares_send.c
  53. 10
      src/lib/ares_str.c
  54. 14
      src/lib/ares_strsplit.c
  55. 6
      src/lib/ares_sysconfig.c
  56. 14
      src/lib/ares_sysconfig_files.c
  57. 98
      src/lib/ares_update_servers.c
  58. 101
      test/ares-test-internal.cc
  59. 97
      test/ares-test-misc.cc
  60. 4
      test/ares-test-parse-a.cc
  61. 4
      test/ares-test-parse-aaaa.cc
  62. 15
      test/ares-test-parse-caa.cc
  63. 3
      test/ares-test-parse-mx.cc
  64. 3
      test/ares-test-parse-naptr.cc
  65. 3
      test/ares-test-parse-ns.cc
  66. 4
      test/ares-test-parse-ptr.cc
  67. 3
      test/ares-test-parse-soa-any.cc
  68. 3
      test/ares-test-parse-soa.cc
  69. 3
      test/ares-test-parse-srv.cc
  70. 5
      test/ares-test-parse-txt.cc
  71. 3
      test/ares-test-parse-uri.cc

@ -63,7 +63,7 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
size_t i;
if (ai == NULL || host == NULL) {
return ARES_EBADQUERY;
return ARES_EBADQUERY; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Use the first node of the response as the family, since hostent can only
@ -74,12 +74,12 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
}
if (family != AF_INET && family != AF_INET6) {
return ARES_EBADQUERY;
return ARES_EBADQUERY; /* LCOV_EXCL_LINE: DefensiveCoding */
}
*host = ares_malloc(sizeof(**host));
if (!(*host)) {
goto enomem;
goto enomem; /* LCOV_EXCL_LINE: OutOfMemory */
}
memset(*host, 0, sizeof(**host));
@ -101,7 +101,7 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
aliases = ares_malloc((naliases + 1) * sizeof(char *));
if (!aliases) {
goto enomem;
goto enomem; /* LCOV_EXCL_LINE: OutOfMemory */
}
(*host)->h_aliases = aliases;
memset(aliases, 0, (naliases + 1) * sizeof(char *));
@ -114,7 +114,7 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
}
aliases[alias] = ares_strdup(next_cname->alias);
if (!aliases[alias]) {
goto enomem;
goto enomem; /* LCOV_EXCL_LINE: OutOfMemory */
}
alias++;
}
@ -123,7 +123,7 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
(*host)->h_addr_list = ares_malloc((naddrs + 1) * sizeof(char *));
if (!(*host)->h_addr_list) {
goto enomem;
goto enomem; /* LCOV_EXCL_LINE: OutOfMemory */
}
memset((*host)->h_addr_list, 0, (naddrs + 1) * sizeof(char *));
@ -131,12 +131,12 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
if (ai->cnames) {
(*host)->h_name = ares_strdup(ai->cnames->name);
if ((*host)->h_name == NULL && ai->cnames->name) {
goto enomem;
goto enomem; /* LCOV_EXCL_LINE: OutOfMemory */
}
} else {
(*host)->h_name = ares_strdup(ai->name);
if ((*host)->h_name == NULL && ai->name) {
goto enomem;
goto enomem; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -153,7 +153,7 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
if (naddrs) {
addrs = ares_malloc(naddrs * (size_t)(*host)->h_length);
if (!addrs) {
goto enomem;
goto enomem; /* LCOV_EXCL_LINE: OutOfMemory */
}
i = 0;
@ -190,10 +190,12 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
return ARES_SUCCESS;
/* LCOV_EXCL_START: OutOfMemory */
enomem:
ares_free_hostent(*host);
*host = NULL;
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
@ -207,23 +209,23 @@ ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
int cname_ttl = INT_MAX;
if (family != AF_INET && family != AF_INET6) {
return ARES_EBADQUERY;
return ARES_EBADQUERY; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ai == NULL || naddrttls == NULL) {
return ARES_EBADQUERY;
return ARES_EBADQUERY; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (family == AF_INET && addrttls == NULL) {
return ARES_EBADQUERY;
return ARES_EBADQUERY; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (family == AF_INET6 && addr6ttls == NULL) {
return ARES_EBADQUERY;
return ARES_EBADQUERY; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (req_naddrttls == 0) {
return ARES_EBADQUERY;
return ARES_EBADQUERY; /* LCOV_EXCL_LINE: DefensiveCoding */
}
*naddrttls = 0;

@ -61,7 +61,7 @@ ares_status_t ares_append_ai_node(int aftype, unsigned short port,
node = ares__append_addrinfo_node(nodes);
if (!node) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
memset(node, 0, sizeof(*node));
@ -69,7 +69,7 @@ ares_status_t ares_append_ai_node(int aftype, unsigned short port,
if (aftype == AF_INET) {
struct sockaddr_in *sin = ares_malloc(sizeof(*sin));
if (!sin) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
memset(sin, 0, sizeof(*sin));
@ -87,7 +87,7 @@ ares_status_t ares_append_ai_node(int aftype, unsigned short port,
if (aftype == AF_INET6) {
struct sockaddr_in6 *sin6 = ares_malloc(sizeof(*sin6));
if (!sin6) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
memset(sin6, 0, sizeof(*sin6));
@ -116,7 +116,7 @@ static ares_status_t
ares_inet_pton(AF_INET6, "::1", &addr6);
status = ares_append_ai_node(AF_INET6, port, 0, &addr6, nodes);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -125,7 +125,7 @@ static ares_status_t
ares_inet_pton(AF_INET, "127.0.0.1", &addr4);
status = ares_append_ai_node(AF_INET, port, 0, &addr4, nodes);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -208,13 +208,13 @@ ares_status_t ares__addrinfo_localhost(const char *name, unsigned short port,
case AF_INET6:
case AF_UNSPEC:
break;
default:
return ARES_EBADFAMILY;
default: /* LCOV_EXCL_LINE: DefensiveCoding */
return ARES_EBADFAMILY; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ai->name = ares_strdup(name);
if (!ai->name) {
goto enomem;
goto enomem; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__system_loopback_addrs(hints->ai_family, port, &nodes);
@ -227,9 +227,11 @@ ares_status_t ares__addrinfo_localhost(const char *name, unsigned short port,
return status;
/* LCOV_EXCL_START: OutOfMemory */
enomem:
ares__freeaddrinfo_nodes(nodes);
ares_free(ai->name);
ai->name = NULL;
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}

@ -87,7 +87,7 @@ void ares__buf_destroy(ares__buf_t *buf)
static ares_bool_t ares__buf_is_const(const ares__buf_t *buf)
{
if (buf == NULL) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (buf->data != NULL && buf->alloc_buf == NULL) {
@ -107,7 +107,7 @@ void ares__buf_reclaim(ares__buf_t *buf)
}
if (ares__buf_is_const(buf)) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Silence coverity. All lengths are zero so would bail out later but
@ -149,7 +149,7 @@ static ares_status_t ares__buf_ensure_space(ares__buf_t *buf,
}
if (ares__buf_is_const(buf)) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* When calling ares__buf_finish_str() we end up adding a null terminator,
@ -199,11 +199,11 @@ static ares_status_t ares__buf_ensure_space(ares__buf_t *buf,
ares_status_t ares__buf_set_length(ares__buf_t *buf, size_t len)
{
if (buf == NULL || ares__buf_is_const(buf)) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (len >= buf->alloc_buf_len - buf->offset) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
buf->data_len = len;
@ -240,12 +240,12 @@ ares_status_t ares__buf_append_be16(ares__buf_t *buf, unsigned short u16)
status = ares__buf_append_byte(buf, (unsigned char)((u16 >> 8) & 0xff));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_byte(buf, (unsigned char)(u16 & 0xff));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_SUCCESS;
@ -257,22 +257,22 @@ ares_status_t ares__buf_append_be32(ares__buf_t *buf, unsigned int u32)
status = ares__buf_append_byte(buf, ((unsigned char)(u32 >> 24) & 0xff));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_byte(buf, ((unsigned char)(u32 >> 16) & 0xff));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_byte(buf, ((unsigned char)(u32 >> 8) & 0xff));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_byte(buf, ((unsigned char)u32 & 0xff));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_SUCCESS;
@ -317,7 +317,7 @@ unsigned char *ares__buf_finish_bin(ares__buf_t *buf, size_t *len)
/* We don't want to return NULL except on failure, may be zero-length */
if (buf->alloc_buf == NULL &&
ares__buf_ensure_space(buf, 1) != ARES_SUCCESS) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
ptr = buf->alloc_buf;
*len = buf->data_len;
@ -538,7 +538,7 @@ ares_status_t ares__buf_fetch_bytes_dup(ares__buf_t *buf, size_t len,
*bytes = ares_malloc(null_term ? len + 1 : len);
if (*bytes == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
memcpy(*bytes, ptr, len);
@ -559,7 +559,7 @@ ares_status_t ares__buf_fetch_str_dup(ares__buf_t *buf, size_t len, char **str)
*str = ares_malloc(len + 1);
if (*str == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
memcpy(*str, ptr, len);
@ -785,7 +785,7 @@ ares_status_t ares__buf_split(ares__buf_t *buf, const unsigned char *delims,
ares_bool_t first = ARES_TRUE;
if (buf == NULL || delims == NULL || delims_len == 0 || list == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
*list = ares__llist_create(ares__buf_destroy_cb);
@ -823,7 +823,7 @@ ares_status_t ares__buf_split(ares__buf_t *buf, const unsigned char *delims,
/* Shouldn't be possible */
if (ptr == NULL) {
status = ARES_EFORMERR;
status = ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done;
}
@ -932,7 +932,7 @@ ares_status_t ares__buf_set_position(ares__buf_t *buf, size_t idx)
}
if (idx > buf->data_len) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
buf->offset = idx;
@ -964,7 +964,7 @@ static ares_status_t ares__buf_parse_dns_binstr_int(
while (orig_len - ares__buf_len(buf) < remaining_len) {
status = ares__buf_fetch_bytes(buf, &len, 1);
if (status != ARES_SUCCESS) {
break;
break; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (len) {
@ -1047,13 +1047,13 @@ ares_status_t ares__buf_append_num_dec(ares__buf_t *buf, size_t num, size_t len)
/* Silence coverity. Shouldn't be possible since we calculate it above */
if (mod == 0) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
digit /= mod;
status = ares__buf_append_byte(buf, '0' + (unsigned char)(digit & 0xFF));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
return ARES_SUCCESS;
@ -1072,7 +1072,7 @@ ares_status_t ares__buf_append_num_hex(ares__buf_t *buf, size_t num, size_t len)
ares_status_t status;
status = ares__buf_append_byte(buf, hexbytes[(num >> ((i - 1) * 4)) & 0xF]);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
return ARES_SUCCESS;
@ -1093,13 +1093,13 @@ static ares_status_t ares__buf_hexdump_line(ares__buf_t *buf, size_t idx,
/* Address */
status = ares__buf_append_num_hex(buf, idx, 6);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* | */
status = ares__buf_append_str(buf, " | ");
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (i = 0; i < 16; i++) {
@ -1109,19 +1109,19 @@ static ares_status_t ares__buf_hexdump_line(ares__buf_t *buf, size_t idx,
status = ares__buf_append_num_hex(buf, data[i], 2);
}
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_byte(buf, ' ');
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
/* | */
status = ares__buf_append_str(buf, " | ");
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (i = 0; i < 16; i++) {
@ -1130,7 +1130,7 @@ static ares_status_t ares__buf_hexdump_line(ares__buf_t *buf, size_t idx,
}
status = ares__buf_append_byte(buf, ares__isprint(data[i]) ? data[i] : '.');
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -1147,7 +1147,7 @@ ares_status_t ares__buf_hexdump(ares__buf_t *buf, const unsigned char *data,
ares_status_t status;
status = ares__buf_hexdump_line(buf, i, data + i, len - i);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -1164,7 +1164,7 @@ ares_status_t ares__buf_load_file(const char *filename, ares__buf_t *buf)
ares_status_t status;
if (filename == NULL || buf == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
fp = fopen(filename, "rb");
@ -1186,39 +1186,39 @@ ares_status_t ares__buf_load_file(const char *filename, ares__buf_t *buf)
/* Get length portably, fstat() is POSIX, not C */
if (fseek(fp, 0, SEEK_END) != 0) {
status = ARES_EFILE;
goto done;
status = ARES_EFILE; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ftell_len = ftell(fp);
if (ftell_len < 0) {
status = ARES_EFILE;
goto done;
status = ARES_EFILE; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
len = (size_t)ftell_len;
if (fseek(fp, 0, SEEK_SET) != 0) {
status = ARES_EFILE;
goto done;
status = ARES_EFILE; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (len == 0) {
status = ARES_SUCCESS;
goto done;
status = ARES_SUCCESS; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Read entire data into buffer */
ptr_len = len;
ptr = ares__buf_append_start(buf, &ptr_len);
if (ptr == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
ptr_len = fread(ptr, 1, len, fp);
if (ptr_len != len) {
status = ARES_EFILE;
goto done;
status = ARES_EFILE; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__buf_append_finish(buf, len);

@ -85,7 +85,7 @@ void ares__check_cleanup_conn(const ares_channel_t *channel,
ares_bool_t do_cleanup = ARES_FALSE;
if (channel == NULL || conn == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ares__llist_len(conn->queries_to_conn)) {

@ -105,7 +105,7 @@ const void *ares_dns_pton(const char *ipaddr, struct ares_addr *addr,
size_t ptr_len = 0;
if (ipaddr == NULL || addr == NULL || out_len == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
*out_len = 0;
@ -150,7 +150,7 @@ static ares_bool_t ares__normalize_ipaddr(const char *ipaddr, char *out,
}
if (!ares_inet_ntop(data.family, addr, out, (ares_socklen_t)out_len)) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return ARES_TRUE;
@ -315,8 +315,8 @@ static ares_status_t ares__hosts_file_add(ares_hosts_file_t *hosts,
if (matchtype != ARES_MATCH_NONE) {
status = ares__hosts_file_merge_entry(hosts, match, entry, matchtype);
if (status != ARES_SUCCESS) {
ares__hosts_entry_destroy(entry);
return status;
ares__hosts_entry_destroy(entry); /* LCOV_EXCL_LINE: DefensiveCoding */
return status; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* entry was invalidated above by merging */
entry = match;
@ -617,7 +617,7 @@ static ares_bool_t ares__hosts_expired(const char *filename,
/* Expire every 60s if we can't get a time */
if (mod_ts == 0) {
mod_ts = time(NULL) - 60;
mod_ts = time(NULL) - 60; /* LCOV_EXCL_LINE: only on systems without stat() */
}
/* If filenames are different, its expired */
@ -642,7 +642,7 @@ static ares_status_t ares__hosts_path(const ares_channel_t *channel,
if (channel->hosts_path) {
path_hosts = ares_strdup(channel->hosts_path);
if (!path_hosts) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -653,7 +653,7 @@ static ares_status_t ares__hosts_path(const ares_channel_t *channel,
path_hosts = ares_strdup(getenv("CARES_HOSTS"));
if (!path_hosts) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -728,7 +728,7 @@ ares_status_t ares__hosts_search_ipaddr(ares_channel_t *channel,
}
if (channel->hf == NULL) {
return ARES_ENOTFOUND;
return ARES_ENOTFOUND; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (!ares__normalize_ipaddr(ipaddr, addr, sizeof(addr))) {
@ -757,7 +757,7 @@ ares_status_t ares__hosts_search_host(ares_channel_t *channel,
}
if (channel->hf == NULL) {
return ARES_ENOTFOUND;
return ARES_ENOTFOUND; /* LCOV_EXCL_LINE: DefensiveCoding */
}
*entry = ares__htable_strvp_get_direct(channel->hf->hosthash, host);
@ -778,8 +778,8 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
*hostent = ares_malloc_zero(sizeof(**hostent));
if (*hostent == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
(*hostent)->h_addrtype = (HOSTENT_ADDRTYPE_TYPE)family;
@ -813,16 +813,16 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
(idx + 1) * sizeof(*(*hostent)->h_addr_list),
(idx + 2) * sizeof(*(*hostent)->h_addr_list));
if (temp == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
(*hostent)->h_addr_list = temp;
(*hostent)->h_addr_list[idx] = ares_malloc(ptr_len);
if ((*hostent)->h_addr_list[idx] == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
memcpy((*hostent)->h_addr_list[idx], ptr, ptr_len);
@ -839,8 +839,8 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
/* Copy main hostname */
(*hostent)->h_name = ares_strdup(ares__llist_first_val(entry->hosts));
if ((*hostent)->h_name == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Copy aliases */
@ -849,14 +849,14 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
/* Cap at 100, some people use https://github.com/StevenBlack/hosts and we
* don't need 200k+ aliases */
if (naliases > 100) {
naliases = 100;
naliases = 100; /* LCOV_EXCL_LINE: DefensiveCoding */
}
(*hostent)->h_aliases =
ares_malloc_zero((naliases + 1) * sizeof(*(*hostent)->h_aliases));
if ((*hostent)->h_aliases == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Copy all entries to the alias except the first */
@ -866,8 +866,8 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
while (node != NULL) {
(*hostent)->h_aliases[idx] = ares_strdup(ares__llist_node_val(node));
if ((*hostent)->h_aliases[idx] == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
idx++;
@ -880,10 +880,12 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
return ARES_SUCCESS;
/* LCOV_EXCL_START: defensive coding */
fail:
ares_free_hostent(*hostent);
*hostent = NULL;
return status;
/* LCOV_EXCL_STOP */
}
static ares_status_t
@ -909,25 +911,25 @@ static ares_status_t
* https://github.com/StevenBlack/hosts and we don't need 200k+ aliases */
cnt++;
if (cnt > 100) {
break;
break; /* LCOV_EXCL_LINE: DefensiveCoding */
}
cname = ares__append_addrinfo_cname(&cnames);
if (cname == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
cname->alias = ares_strdup(host);
if (cname->alias == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
cname->name = ares_strdup(primaryhost);
if (cname->name == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
node = ares__llist_node_next(node);
@ -937,22 +939,22 @@ static ares_status_t
if (cnames == NULL) {
cname = ares__append_addrinfo_cname(&cnames);
if (cname == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
cname->name = ares_strdup(primaryhost);
if (cname->name == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
status = ARES_SUCCESS;
done:
if (status != ARES_SUCCESS) {
ares__freeaddrinfo_cnames(cnames);
return status;
ares__freeaddrinfo_cnames(cnames); /* LCOV_EXCL_LINE: DefensiveCoding */
return status; /* LCOV_EXCL_LINE: DefensiveCoding */
}
*cnames_out = cnames;
@ -975,14 +977,14 @@ ares_status_t ares__hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry,
case AF_INET6:
case AF_UNSPEC:
break;
default:
return ARES_EBADFAMILY;
default: /* LCOV_EXCL_LINE: DefensiveCoding */
return ARES_EBADFAMILY; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ai->name = ares_strdup(name);
if (ai->name == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (node = ares__llist_node_first(entry->ips); node != NULL;
@ -1002,14 +1004,14 @@ ares_status_t ares__hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry,
status = ares_append_ai_node(addr.family, port, 0, ptr, &ainodes);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
}
if (want_cnames) {
status = ares__hosts_ai_append_cnames(entry, &cnames);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
}
@ -1017,11 +1019,13 @@ ares_status_t ares__hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry,
done:
if (status != ARES_SUCCESS) {
/* LCOV_EXCL_START: defensive coding */
ares__freeaddrinfo_cnames(cnames);
ares__freeaddrinfo_nodes(ainodes);
ares_free(ai->name);
ai->name = NULL;
return status;
/* LCOV_EXCL_STOP */
}
ares__addrinfo_cat_cnames(&ai->cnames, cnames);
ares__addrinfo_cat_nodes(&ai->nodes, ainodes);

@ -121,7 +121,7 @@ ares_socket_t *ares__htable_asvp_keys(const ares__htable_asvp_t *htable,
size_t i;
if (htable == NULL || num == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
*num = 0;
@ -133,8 +133,8 @@ ares_socket_t *ares__htable_asvp_keys(const ares__htable_asvp_t *htable,
out = ares_malloc_zero(sizeof(*out) * cnt);
if (out == NULL) {
ares_free(buckets);
return NULL;
ares_free(buckets); /* LCOV_EXCL_LINE: OutOfMemory */
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (i = 0; i < cnt; i++) {
@ -157,7 +157,7 @@ ares_bool_t ares__htable_asvp_insert(ares__htable_asvp_t *htable,
bucket = ares_malloc(sizeof(*bucket));
if (bucket == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
bucket->parent = htable;
@ -165,14 +165,14 @@ ares_bool_t ares__htable_asvp_insert(ares__htable_asvp_t *htable,
bucket->val = val;
if (!ares__htable_insert(htable->hash, bucket)) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_TRUE;
fail:
if (bucket) {
ares_free(bucket);
ares_free(bucket); /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_FALSE;
}

@ -123,7 +123,7 @@ ares_bool_t ares__htable_szvp_insert(ares__htable_szvp_t *htable, size_t key,
bucket = ares_malloc(sizeof(*bucket));
if (bucket == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
bucket->parent = htable;
@ -131,14 +131,14 @@ ares_bool_t ares__htable_szvp_insert(ares__htable_szvp_t *htable, size_t key,
bucket->val = val;
if (!ares__htable_insert(htable->hash, bucket)) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_TRUE;
fail:
if (bucket) {
ares_free(bucket);
ares_free(bucket); /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_FALSE;
}

@ -44,7 +44,7 @@ typedef struct {
void ares__htable_vpvp_destroy(ares__htable_vpvp_t *htable)
{
if (htable == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__htable_destroy(htable->hash);
@ -93,13 +93,13 @@ ares__htable_vpvp_t *
{
ares__htable_vpvp_t *htable = ares_malloc(sizeof(*htable));
if (htable == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
htable->hash =
ares__htable_create(hash_func, bucket_key, bucket_free, key_eq);
if (htable->hash == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
htable->free_key = key_free;
@ -107,12 +107,14 @@ ares__htable_vpvp_t *
return htable;
/* LCOV_EXCL_START: OutOfMemory */
fail:
if (htable) {
ares__htable_destroy(htable->hash);
ares_free(htable);
}
return NULL;
/* LCOV_EXCL_STOP */
}
ares_bool_t ares__htable_vpvp_insert(ares__htable_vpvp_t *htable, void *key,

@ -81,15 +81,15 @@ static ares__iface_ips_t *ares__iface_ips_alloc(ares__iface_ip_flags_t flags)
{
ares__iface_ips_t *ips = ares_malloc_zero(sizeof(*ips));
if (ips == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Prealloc 4 entries */
ips->alloc_size = 4;
ips->ips = ares_malloc_zero(ips->alloc_size * sizeof(*ips->ips));
if (ips->ips == NULL) {
ares_free(ips);
return NULL;
ares_free(ips); /* LCOV_EXCL_LINE: OutOfMemory */
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
ips->enum_flags = flags;
return ips;
@ -98,7 +98,7 @@ static ares__iface_ips_t *ares__iface_ips_alloc(ares__iface_ip_flags_t flags)
static void ares__iface_ip_destroy(ares__iface_ip_t *ip)
{
if (ip == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares_free(ip->name);
memset(ip, 0, sizeof(*ip));
@ -130,14 +130,16 @@ ares_status_t ares__iface_ips(ares__iface_ips_t **ips,
*ips = ares__iface_ips_alloc(flags);
if (*ips == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__iface_ips_enumerate(*ips, name);
if (status != ARES_SUCCESS) {
/* LCOV_EXCL_START: UntestablePath */
ares__iface_ips_destroy(*ips);
*ips = NULL;
return status;
/* LCOV_EXCL_STOP */
}
return ARES_SUCCESS;
@ -151,7 +153,7 @@ static ares_status_t
size_t idx;
if (ips == NULL || name == NULL || addr == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Don't want loopback */
@ -204,7 +206,7 @@ static ares_status_t
temp = ares_realloc_zero(ips->ips, ips->alloc_size * sizeof(*ips->ips),
alloc_size * sizeof(*ips->ips));
if (temp == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
ips->ips = temp;
ips->alloc_size = alloc_size;
@ -215,11 +217,13 @@ static ares_status_t
ips->ips[idx].flags = flags;
ips->ips[idx].netmask = netmask;
ips->ips[idx].ll_scope = ll_scope;
if (flags & ARES_IFACE_IP_LINKLOCAL) {
ips->ips[idx].ll_scope = ll_scope;
}
memcpy(&ips->ips[idx].addr, addr, sizeof(*addr));
ips->ips[idx].name = ares_strdup(name);
if (ips->ips[idx].name == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_SUCCESS;
@ -490,7 +494,7 @@ static ares_status_t ares__iface_ips_enumerate(ares__iface_ips_t *ips,
}
/* Name mismatch */
if (strcasecmp(ifa->ifa_name, name) != 0) {
if (name != NULL && strcasecmp(ifa->ifa_name, name) != 0) {
continue;
}
@ -522,6 +526,8 @@ static ares_status_t ares__iface_ips_enumerate(ares__iface_ips_t *ips,
unsigned int ares__if_nametoindex(const char *name)
{
#ifdef HAVE_IF_NAMETOINDEX
if (name == NULL)
return 0;
return if_nametoindex(name);
#else
ares_status_t status;
@ -529,6 +535,9 @@ unsigned int ares__if_nametoindex(const char *name)
size_t i;
unsigned int index = 0;
if (name == NULL)
return 0;
status =
ares__iface_ips(&ips, ARES_IFACE_IP_V6 | ARES_IFACE_IP_LINKLOCAL, name);
if (status != ARES_SUCCESS) {
@ -562,7 +571,7 @@ const char *ares__if_indextoname(unsigned int index, char *name,
size_t i;
const char *ptr = NULL;
if (name_len < IF_NAMESIZE) {
if (name == NULL || name_len < IF_NAMESIZE) {
goto done;
}

@ -77,7 +77,7 @@ static void ares__llist_attach_at(ares__llist_t *list,
ares__llist_node_t *node)
{
if (list == NULL || node == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
node->parent = list;
@ -127,7 +127,7 @@ static ares__llist_node_t *ares__llist_insert_at(ares__llist_t *list,
ares__llist_node_t *node = NULL;
if (list == NULL || val == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
node = ares_malloc_zero(sizeof(*node));
@ -250,7 +250,7 @@ static void ares__llist_node_detach(ares__llist_node_t *node)
ares__llist_t *list;
if (node == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
list = node->parent;
@ -341,7 +341,7 @@ void ares__llist_node_move_parent_last(ares__llist_node_t *node,
ares__llist_t *new_parent)
{
if (node == NULL || new_parent == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__llist_node_detach(node);
@ -352,7 +352,7 @@ void ares__llist_node_move_parent_first(ares__llist_node_t *node,
ares__llist_t *new_parent)
{
if (node == NULL || new_parent == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__llist_node_detach(node);

@ -65,7 +65,7 @@ ares_status_t ares__parse_into_addrinfo(const ares_dns_record_t *dnsrec,
/* Save question hostname */
status = ares_dns_record_query_get(dnsrec, 0, &hostname, NULL, NULL);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ancount = ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ANSWER);
@ -107,19 +107,19 @@ ares_status_t ares__parse_into_addrinfo(const ares_dns_record_t *dnsrec,
cname = ares__append_addrinfo_cname(&cnames);
if (cname == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
cname->ttl = (int)ares_dns_rr_get_ttl(rr);
cname->alias = ares_strdup(ares_dns_rr_get_name(rr));
if (cname->alias == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
cname->name = ares_strdup(hostname);
if (cname->name == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
} else if (rtype == ARES_REC_TYPE_A) {
got_a = ARES_TRUE;
@ -127,7 +127,7 @@ ares_status_t ares__parse_into_addrinfo(const ares_dns_record_t *dnsrec,
ares_append_ai_node(AF_INET, port, ares_dns_rr_get_ttl(rr),
ares_dns_rr_get_addr(rr, ARES_RR_A_ADDR), &nodes);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
} else if (rtype == ARES_REC_TYPE_AAAA) {
got_aaaa = ARES_TRUE;
@ -135,7 +135,7 @@ ares_status_t ares__parse_into_addrinfo(const ares_dns_record_t *dnsrec,
ares_dns_rr_get_addr6(rr, ARES_RR_AAAA_ADDR),
&nodes);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
} else {
continue;
@ -153,8 +153,8 @@ ares_status_t ares__parse_into_addrinfo(const ares_dns_record_t *dnsrec,
ares_free(ai->name);
ai->name = ares_strdup(hostname);
if (ai->name == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}

@ -206,7 +206,7 @@ ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val)
node = ares_malloc_zero(sizeof(*node));
if (node == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
node->data = val;
@ -218,12 +218,12 @@ ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val)
/* Allocate array of next and prev nodes for linking each level */
node->next = ares_malloc_zero(sizeof(*node->next) * node->levels);
if (node->next == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
node->prev = ares_malloc_zero(sizeof(*node->prev) * node->levels);
if (node->prev == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* If the number of levels is greater than we currently support in the slist,
@ -233,7 +233,7 @@ ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val)
ares_realloc_zero(list->head, sizeof(*list->head) * list->levels,
sizeof(*list->head) * node->levels);
if (ptr == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
list->head = ptr;
@ -246,6 +246,7 @@ ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val)
return node;
/* LCOV_EXCL_START: OutOfMemory */
fail:
if (node) {
ares_free(node->prev);
@ -253,6 +254,7 @@ fail:
ares_free(node);
}
return NULL;
/* LCOV_EXCL_STOP */
}
static void ares__slist_node_pop(ares__slist_node_t *node)

@ -191,14 +191,14 @@ static int configure_socket(ares_socket_t s, struct server_state *server)
setsockopt(s, SOL_SOCKET, SO_SNDBUF,
(void *)&channel->socket_send_buffer_size,
sizeof(channel->socket_send_buffer_size)) == -1) {
return -1;
return -1; /* LCOV_EXCL_LINE: UntestablePath */
}
if ((channel->socket_receive_buffer_size > 0) &&
setsockopt(s, SOL_SOCKET, SO_RCVBUF,
(void *)&channel->socket_receive_buffer_size,
sizeof(channel->socket_receive_buffer_size)) == -1) {
return -1;
return -1; /* LCOV_EXCL_LINE: UntestablePath */
}
#ifdef SO_BINDTODEVICE
@ -304,8 +304,8 @@ ares_status_t ares__open_connection(ares_channel_t *channel,
if ((!channel->sock_funcs || !channel->sock_funcs->asocket) &&
setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (void *)&opt, sizeof(opt)) ==
-1) {
ares__close_socket(channel, s);
return ARES_ECONNREFUSED;
ares__close_socket(channel, s); /* LCOV_EXCL_LINE: UntestablePath */
return ARES_ECONNREFUSED; /* LCOV_EXCL_LINE: UntestablePath */
}
}
#endif
@ -338,8 +338,8 @@ ares_status_t ares__open_connection(ares_channel_t *channel,
conn = ares_malloc(sizeof(*conn));
if (conn == NULL) {
ares__close_socket(channel, s);
return ARES_ENOMEM;
ares__close_socket(channel, s); /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
memset(conn, 0, sizeof(*conn));
conn->fd = s;
@ -347,9 +347,11 @@ ares_status_t ares__open_connection(ares_channel_t *channel,
conn->queries_to_conn = ares__llist_create(NULL);
conn->is_tcp = is_tcp;
if (conn->queries_to_conn == NULL) {
/* LCOV_EXCL_START: OutOfMemory */
ares__close_socket(channel, s);
ares_free(conn);
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
/* TCP connections are thrown to the end as we don't spawn multiple TCP
@ -361,20 +363,24 @@ ares_status_t ares__open_connection(ares_channel_t *channel,
node = ares__llist_insert_first(server->connections, conn);
}
if (node == NULL) {
/* LCOV_EXCL_START: OutOfMemory */
ares__close_socket(channel, s);
ares__llist_destroy(conn->queries_to_conn);
ares_free(conn);
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
/* Register globally to quickly map event on file descriptor to connection
* node object */
if (!ares__htable_asvp_insert(channel->connnode_by_socket, s, node)) {
/* LCOV_EXCL_START: OutOfMemory */
ares__close_socket(channel, s);
ares__llist_destroy(conn->queries_to_conn);
ares__llist_node_claim(node);
ares_free(conn);
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
SOCK_STATE_CALLBACK(channel, s, 1, 0);

@ -226,25 +226,27 @@ ares__thread_mutex_t *ares__thread_mutex_create(void)
}
if (pthread_mutexattr_init(&attr) != 0) {
ares_free(mut);
return NULL;
ares_free(mut); /* LCOV_EXCL_LINE: UntestablePath */
return NULL; /* LCOV_EXCL_LINE: UntestablePath */
}
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: UntestablePath */
}
if (pthread_mutex_init(&mut->mutex, &attr) != 0) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: UntestablePath */
}
pthread_mutexattr_destroy(&attr);
return mut;
/* LCOV_EXCL_START: UntestablePath */
fail:
pthread_mutexattr_destroy(&attr);
ares_free(mut);
return NULL;
/* LCOV_EXCL_STOP */
}
void ares__thread_mutex_destroy(ares__thread_mutex_t *mut)
@ -379,11 +381,11 @@ ares_status_t ares__thread_create(ares__thread_t **thread,
thr = ares_malloc_zero(sizeof(*thr));
if (thr == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (pthread_create(&thr->thread, NULL, func, arg) != 0) {
ares_free(thr);
return ARES_ESERVFAIL;
ares_free(thr); /* LCOV_EXCL_LINE: UntestablePath */
return ARES_ESERVFAIL; /* LCOV_EXCL_LINE: UntestablePath */
}
*thread = thr;

@ -57,10 +57,12 @@ ares_timeval_t ares__tvnow(void)
now.sec = (ares_int64_t)tsnow.tv_sec;
now.usec = (unsigned int)(tsnow.tv_nsec / 1000);
} else {
/* LCOV_EXCL_START: FallbackCode */
struct timeval tv;
(void)gettimeofday(&tv, NULL);
now.sec = (ares_int64_t)tv.tv_sec;
now.usec = (unsigned int)tv.tv_usec;
/* LCOV_EXCL_STOP */
}
return now;
}

@ -57,8 +57,8 @@ void ares_cancel(ares_channel_t *channel)
/* Out of memory, this function doesn't return a result code though so we
* can't report to caller */
if (channel->all_queries == NULL) {
channel->all_queries = list_copy;
goto done;
channel->all_queries = list_copy; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
node = ares__llist_node_first(list_copy);

@ -129,7 +129,7 @@ void ares_destroy(ares_channel_t *channel)
void ares__destroy_server(struct server_state *server)
{
if (server == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__close_sockets(server);

@ -37,7 +37,7 @@ static void ares__nameoffset_free(void *arg)
{
ares_nameoffset_t *off = arg;
if (off == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares_free(off->name);
ares_free(off);
@ -51,20 +51,20 @@ static ares_status_t ares__nameoffset_create(ares__llist_t **list,
if (list == NULL || name == NULL || ares_strlen(name) == 0 ||
ares_strlen(name) > 255) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (*list == NULL) {
*list = ares__llist_create(ares__nameoffset_free);
}
if (*list == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
off = ares_malloc_zero(sizeof(*off));
if (off == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
off->name = ares_strdup(name);
@ -72,15 +72,17 @@ static ares_status_t ares__nameoffset_create(ares__llist_t **list,
off->idx = idx;
if (ares__llist_insert_last(*list, off) == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_SUCCESS;
/* LCOV_EXCL_START: OutOfMemory */
fail:
ares__nameoffset_free(off);
return status;
/* LCOV_EXCL_STOP */
}
static const ares_nameoffset_t *ares__nameoffset_find(ares__llist_t *list,
@ -138,7 +140,7 @@ static void ares_dns_labels_free(ares_dns_labels_t *labels)
size_t i;
if (labels == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
for (i = 0; i < labels->num; i++) {
@ -155,20 +157,20 @@ static ares__buf_t *ares_dns_labels_add(ares_dns_labels_t *labels)
void *temp;
if (labels == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
temp = ares_realloc_zero(labels->label, sizeof(*labels->label) * labels->num,
sizeof(*labels->label) * (labels->num + 1));
if (temp == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
labels->label = temp;
labels->label[labels->num] = ares__buf_create();
if (labels->label[labels->num] == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
labels->num++;
@ -179,7 +181,7 @@ static const ares__buf_t *
ares_dns_labels_get_last(const ares_dns_labels_t *labels)
{
if (labels == NULL || labels->num == 0) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return labels->label[labels->num - 1];
@ -188,7 +190,7 @@ static const ares__buf_t *
static void ares_dns_name_labels_del_last(ares_dns_labels_t *labels)
{
if (labels == NULL || labels->num == 0) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__buf_destroy(labels->label[labels->num - 1]);
@ -260,29 +262,29 @@ static ares_status_t ares_split_dns_name(ares_dns_labels_t *labels,
unsigned char c;
if (name == NULL || labels == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Put name into a buffer for parsing */
namebuf = ares__buf_create();
if (namebuf == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (*name != '\0') {
status =
ares__buf_append(namebuf, (const unsigned char *)name, ares_strlen(name));
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
/* Start with 1 label */
label = ares_dns_labels_add(labels);
if (label == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
while (ares__buf_fetch_bytes(namebuf, &c, 1) == ARES_SUCCESS) {
@ -290,8 +292,8 @@ static ares_status_t ares_split_dns_name(ares_dns_labels_t *labels,
if (c == '.') {
label = ares_dns_labels_add(labels);
if (label == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
continue;
}
@ -313,7 +315,7 @@ static ares_status_t ares_split_dns_name(ares_dns_labels_t *labels,
status = ares__buf_append_byte(label, c);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -369,7 +371,7 @@ ares_status_t ares__dns_name_write(ares__buf_t *buf, ares__llist_t **list,
ares_status_t status;
if (buf == NULL || name == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
memset(&labels, 0, sizeof(labels));
@ -404,12 +406,12 @@ ares_status_t ares__dns_name_write(ares__buf_t *buf, ares__llist_t **list,
status = ares__buf_append_byte(buf, (unsigned char)(len & 0xFF));
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append(buf, ptr, len);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -417,7 +419,7 @@ ares_status_t ares__dns_name_write(ares__buf_t *buf, ares__llist_t **list,
if (off == NULL) {
status = ares__buf_append_byte(buf, 0);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -428,7 +430,7 @@ ares_status_t ares__dns_name_write(ares__buf_t *buf, ares__llist_t **list,
(unsigned short)0xC000 | (unsigned short)(off->idx & 0x3FFF);
status = ares__buf_append_be16(buf, u16);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -438,7 +440,7 @@ ares_status_t ares__dns_name_write(ares__buf_t *buf, ares__llist_t **list,
name_len > 0) {
status = ares__nameoffset_create(list, name /* not truncated copy! */, pos);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -509,7 +511,7 @@ static ares_status_t ares__fetch_dnsname_into_buf(ares__buf_t *buf,
status = ares__buf_append(dest, escape, sizeof(escape));
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
continue;
@ -519,13 +521,13 @@ static ares_status_t ares__fetch_dnsname_into_buf(ares__buf_t *buf,
if (is_reservedch(c)) {
status = ares__buf_append_byte(dest, '\\');
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
status = ares__buf_append_byte(dest, c);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -641,7 +643,7 @@ ares_status_t ares__dns_name_parse(ares__buf_t *buf, char **name,
if (ares__buf_len(namebuf) != 0 && name != NULL) {
status = ares__buf_append_byte(namebuf, '.');
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -660,8 +662,8 @@ ares_status_t ares__dns_name_parse(ares__buf_t *buf, char **name,
if (name != NULL) {
*name = ares__buf_finish_str(namebuf, NULL);
if (*name == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}

@ -925,7 +925,7 @@ static ares_status_t ares_dns_parse_header(ares__buf_t *buf, unsigned int flags,
status =
ares_dns_record_rr_prealloc(*dnsrec, ARES_SECTION_ANSWER, *ancount);
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -933,7 +933,7 @@ static ares_status_t ares_dns_parse_header(ares__buf_t *buf, unsigned int flags,
status =
ares_dns_record_rr_prealloc(*dnsrec, ARES_SECTION_AUTHORITY, *nscount);
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -941,7 +941,7 @@ static ares_status_t ares_dns_parse_header(ares__buf_t *buf, unsigned int flags,
status =
ares_dns_record_rr_prealloc(*dnsrec, ARES_SECTION_ADDITIONAL, *arcount);
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -1216,7 +1216,7 @@ static ares_status_t ares_dns_parse_buf(ares__buf_t *buf, unsigned int flags,
unsigned short i;
if (buf == NULL || dnsrec == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Maximum DNS packet size is 64k, even over TCP */

@ -292,8 +292,8 @@ ares_status_t ares_dns_record_query_set_name(ares_dns_record_t *dnsrec,
orig_name = dnsrec->qd[idx].name;
dnsrec->qd[idx].name = ares_strdup(name);
if (dnsrec->qd[idx].name == NULL) {
dnsrec->qd[idx].name = orig_name;
return ARES_ENOMEM;
dnsrec->qd[idx].name = orig_name; /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
ares_free(orig_name);
@ -354,7 +354,7 @@ size_t ares_dns_record_rr_cnt(const ares_dns_record_t *dnsrec,
return dnsrec->arcount;
}
return 0;
return 0; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares_status_t ares_dns_record_rr_prealloc(ares_dns_record_t *dnsrec,
@ -365,7 +365,7 @@ ares_status_t ares_dns_record_rr_prealloc(ares_dns_record_t *dnsrec,
ares_dns_rr_t *temp = NULL;
if (dnsrec == NULL || cnt == 0 || !ares_dns_section_isvalid(sect)) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
switch (sect) {
@ -440,7 +440,7 @@ ares_status_t ares_dns_record_rr_add(ares_dns_rr_t **rr_out,
status = ares_dns_record_rr_prealloc(dnsrec, sect, *rr_len + 1);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
idx = *rr_len;
@ -580,7 +580,7 @@ static void *ares_dns_rr_data_ptr(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
size_t **lenptr)
{
if (dns_rr == NULL || dns_rr->type != ares_dns_rr_key_to_rec_type(key)) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
switch (key) {

@ -44,7 +44,7 @@ static ares_status_t ares_dns_write_header(const ares_dns_record_t *dnsrec,
/* ID */
status = ares__buf_append_be16(buf, dnsrec->id);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Flags */
@ -103,31 +103,31 @@ static ares_status_t ares_dns_write_header(const ares_dns_record_t *dnsrec,
status = ares__buf_append_be16(buf, u16);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* QDCOUNT */
status = ares__buf_append_be16(buf, (unsigned short)dnsrec->qdcount);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* ANCOUNT */
status = ares__buf_append_be16(buf, (unsigned short)dnsrec->ancount);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* NSCOUNT */
status = ares__buf_append_be16(buf, (unsigned short)dnsrec->nscount);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* ARCOUNT */
status = ares__buf_append_be16(buf, (unsigned short)dnsrec->arcount);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_SUCCESS;
@ -159,13 +159,13 @@ static ares_status_t ares_dns_write_questions(const ares_dns_record_t *dnsrec,
/* Type */
status = ares__buf_append_be16(buf, (unsigned short)qtype);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Class */
status = ares__buf_append_be16(buf, (unsigned short)qclass);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -182,7 +182,7 @@ static ares_status_t ares_dns_write_rr_name(ares__buf_t *buf,
name = ares_dns_rr_get_str(rr, key);
if (name == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return ares__dns_name_write(buf, namelist, validate_hostname, name);
@ -198,7 +198,7 @@ static ares_status_t ares_dns_write_rr_str(ares__buf_t *buf,
str = ares_dns_rr_get_str(rr, key);
if (str == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
len = ares_strlen(str);
@ -209,7 +209,7 @@ static ares_status_t ares_dns_write_rr_str(ares__buf_t *buf,
/* Write 1 byte length */
status = ares__buf_append_byte(buf, (unsigned char)(len & 0xFF));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (len == 0) {
@ -232,7 +232,7 @@ static ares_status_t ares_dns_write_rr_binstrs(ares__buf_t *buf,
bin = ares_dns_rr_get_bin(rr, key, &bin_len);
if (bin == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* split into possible multiple 255-byte or less length strings */
ptr = bin;
@ -246,14 +246,14 @@ static ares_status_t ares_dns_write_rr_binstrs(ares__buf_t *buf,
/* Length */
status = ares__buf_append_byte(buf, (unsigned char)(len & 0xFF));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* String */
if (len) {
status = ares__buf_append(buf, ptr, len);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -269,7 +269,7 @@ static ares_status_t ares_dns_write_rr_be32(ares__buf_t *buf,
ares_dns_rr_key_t key)
{
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_U32) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return ares__buf_append_be32(buf, ares_dns_rr_get_u32(rr, key));
}
@ -279,7 +279,7 @@ static ares_status_t ares_dns_write_rr_be16(ares__buf_t *buf,
ares_dns_rr_key_t key)
{
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_U16) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return ares__buf_append_be16(buf, ares_dns_rr_get_u16(rr, key));
}
@ -289,7 +289,7 @@ static ares_status_t ares_dns_write_rr_u8(ares__buf_t *buf,
ares_dns_rr_key_t key)
{
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_U8) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return ares__buf_append_byte(buf, ares_dns_rr_get_u8(rr, key));
}
@ -303,7 +303,7 @@ static ares_status_t ares_dns_write_rr_a(ares__buf_t *buf,
addr = ares_dns_rr_get_addr(rr, ARES_RR_A_ADDR);
if (addr == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return ares__buf_append(buf, (const unsigned char *)addr, sizeof(*addr));
@ -348,25 +348,25 @@ static ares_status_t ares_dns_write_rr_soa(ares__buf_t *buf,
/* SERIAL */
status = ares_dns_write_rr_be32(buf, rr, ARES_RR_SOA_SERIAL);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* REFRESH */
status = ares_dns_write_rr_be32(buf, rr, ARES_RR_SOA_REFRESH);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* RETRY */
status = ares_dns_write_rr_be32(buf, rr, ARES_RR_SOA_RETRY);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* EXPIRE */
status = ares_dns_write_rr_be32(buf, rr, ARES_RR_SOA_EXPIRE);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* MINIMUM */
@ -408,7 +408,7 @@ static ares_status_t ares_dns_write_rr_mx(ares__buf_t *buf,
/* PREFERENCE */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_MX_PREFERENCE);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* EXCHANGE */
@ -437,43 +437,43 @@ static ares_status_t ares_dns_write_rr_sig(ares__buf_t *buf,
/* TYPE COVERED */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_SIG_TYPE_COVERED);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* ALGORITHM */
status = ares_dns_write_rr_u8(buf, rr, ARES_RR_SIG_ALGORITHM);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* LABELS */
status = ares_dns_write_rr_u8(buf, rr, ARES_RR_SIG_LABELS);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* ORIGINAL TTL */
status = ares_dns_write_rr_be32(buf, rr, ARES_RR_SIG_ORIGINAL_TTL);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* EXPIRATION */
status = ares_dns_write_rr_be32(buf, rr, ARES_RR_SIG_EXPIRATION);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* INCEPTION */
status = ares_dns_write_rr_be32(buf, rr, ARES_RR_SIG_INCEPTION);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* KEY TAG */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_SIG_KEY_TAG);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* SIGNERS NAME */
@ -501,7 +501,7 @@ static ares_status_t ares_dns_write_rr_aaaa(ares__buf_t *buf,
addr = ares_dns_rr_get_addr6(rr, ARES_RR_AAAA_ADDR);
if (addr == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return ares__buf_append(buf, (const unsigned char *)addr, sizeof(*addr));
@ -516,19 +516,19 @@ static ares_status_t ares_dns_write_rr_srv(ares__buf_t *buf,
/* PRIORITY */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_SRV_PRIORITY);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* WEIGHT */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_SRV_WEIGHT);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* PORT */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_SRV_PORT);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* TARGET */
@ -545,31 +545,31 @@ static ares_status_t ares_dns_write_rr_naptr(ares__buf_t *buf,
/* ORDER */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_NAPTR_ORDER);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* PREFERENCE */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_NAPTR_PREFERENCE);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* FLAGS */
status = ares_dns_write_rr_str(buf, rr, ARES_RR_NAPTR_FLAGS);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* SERVICES */
status = ares_dns_write_rr_str(buf, rr, ARES_RR_NAPTR_SERVICES);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* REGEXP */
status = ares_dns_write_rr_str(buf, rr, ARES_RR_NAPTR_REGEXP);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* REPLACEMENT */
@ -601,7 +601,7 @@ static ares_status_t ares_dns_write_rr_opt(ares__buf_t *buf,
/* Class -> UDP Size */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_OPT_UDP_SIZE);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* TTL -> rcode (u8) << 24 | version (u8) << 16 | flags (u16) */
@ -611,7 +611,7 @@ static ares_status_t ares_dns_write_rr_opt(ares__buf_t *buf,
status = ares__buf_append_be32(buf, ttl);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Now go back to real end */
@ -631,20 +631,20 @@ static ares_status_t ares_dns_write_rr_opt(ares__buf_t *buf,
/* BE16 option */
status = ares__buf_append_be16(buf, opt);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* BE16 length */
status = ares__buf_append_be16(buf, (unsigned short)(val_len & 0xFFFF));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Value */
if (val && val_len) {
status = ares__buf_append(buf, val, val_len);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -665,19 +665,19 @@ static ares_status_t ares_dns_write_rr_tlsa(ares__buf_t *buf,
/* CERT_USAGE */
status = ares_dns_write_rr_u8(buf, rr, ARES_RR_TLSA_CERT_USAGE);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* SELECTOR */
status = ares_dns_write_rr_u8(buf, rr, ARES_RR_TLSA_SELECTOR);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* MATCH */
status = ares_dns_write_rr_u8(buf, rr, ARES_RR_TLSA_MATCH);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* DATA -- binary, rest of buffer, required to be non-zero length */
@ -699,7 +699,7 @@ static ares_status_t ares_dns_write_rr_svcb(ares__buf_t *buf,
/* PRIORITY */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_SVCB_PRIORITY);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* TARGET */
@ -720,20 +720,20 @@ static ares_status_t ares_dns_write_rr_svcb(ares__buf_t *buf,
/* BE16 option */
status = ares__buf_append_be16(buf, opt);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* BE16 length */
status = ares__buf_append_be16(buf, (unsigned short)(val_len & 0xFFFF));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Value */
if (val && val_len) {
status = ares__buf_append(buf, val, val_len);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -750,7 +750,7 @@ static ares_status_t ares_dns_write_rr_https(ares__buf_t *buf,
/* PRIORITY */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_HTTPS_PRIORITY);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* TARGET */
@ -771,20 +771,20 @@ static ares_status_t ares_dns_write_rr_https(ares__buf_t *buf,
/* BE16 option */
status = ares__buf_append_be16(buf, opt);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* BE16 length */
status = ares__buf_append_be16(buf, (unsigned short)(val_len & 0xFFFF));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Value */
if (val && val_len) {
status = ares__buf_append(buf, val, val_len);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -803,13 +803,13 @@ static ares_status_t ares_dns_write_rr_uri(ares__buf_t *buf,
/* PRIORITY */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_URI_PRIORITY);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* WEIGHT */
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_URI_WEIGHT);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* TARGET -- not in DNS string format, rest of buffer, required to be
@ -836,13 +836,13 @@ static ares_status_t ares_dns_write_rr_caa(ares__buf_t *buf,
/* CRITICAL */
status = ares_dns_write_rr_u8(buf, rr, ARES_RR_CAA_CRITICAL);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Tag */
status = ares_dns_write_rr_str(buf, rr, ARES_RR_CAA_TAG);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Value - binary! (remaining buffer */
@ -877,7 +877,7 @@ static ares_status_t ares_dns_write_rr_raw_rr(ares__buf_t *buf,
status = ares_dns_write_rr_be16(buf, rr, ARES_RR_RAW_RR_TYPE);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Now go back to real end */
@ -919,7 +919,7 @@ static ares_status_t ares_dns_write_rr(const ares_dns_record_t *dnsrec,
rr = ares_dns_record_rr_get_const(dnsrec, section, i);
if (rr == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
type = ares_dns_rr_get_type(rr);
@ -938,14 +938,14 @@ static ares_status_t ares_dns_write_rr(const ares_dns_record_t *dnsrec,
/* Type */
status = ares__buf_append_be16(buf, (unsigned short)type);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Class */
status =
ares__buf_append_be16(buf, (unsigned short)ares_dns_rr_get_class(rr));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* TTL */
@ -957,14 +957,14 @@ static ares_status_t ares_dns_write_rr(const ares_dns_record_t *dnsrec,
}
status = ares__buf_append_be32(buf, ttl);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Length */
pos_len = ares__buf_len(buf); /* Save to write real length later */
status = ares__buf_append_be16(buf, 0);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Data */
@ -1047,7 +1047,7 @@ static ares_status_t ares_dns_write_rr(const ares_dns_record_t *dnsrec,
status = ares__buf_append_be16(buf, (unsigned short)(rdlength & 0xFFFF));
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_set_length(buf, end_length);
@ -1075,7 +1075,7 @@ ares_status_t ares_dns_write(const ares_dns_record_t *dnsrec,
b = ares__buf_create();
if (b == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares_dns_write_header(dnsrec, b);

@ -54,7 +54,7 @@ struct ares_event_configchg {
void ares_event_configchg_destroy(ares_event_configchg_t *configchg)
{
if (configchg == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Tell event system to stop monitoring for changes. This will cause the
@ -67,7 +67,7 @@ static void ares_event_configchg_free(void *data)
{
ares_event_configchg_t *configchg = data;
if (configchg == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (configchg->inotify_fd >= 0) {
@ -142,22 +142,22 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg,
c = ares_malloc_zero(sizeof(*c));
if (c == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
c->e = e;
c->inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if (c->inotify_fd == -1) {
status = ARES_ESERVFAIL;
goto done;
status = ARES_ESERVFAIL; /* LCOV_EXCL_LINE: UntestablePath */
goto done; /* LCOV_EXCL_LINE: UntestablePath */
}
/* We need to monitor /etc/resolv.conf, /etc/nsswitch.conf */
if (inotify_add_watch(c->inotify_fd, "/etc",
IN_CREATE | IN_MODIFY | IN_MOVED_TO | IN_ONLYDIR) ==
-1) {
status = ARES_ESERVFAIL;
goto done;
status = ARES_ESERVFAIL; /* LCOV_EXCL_LINE: UntestablePath */
goto done; /* LCOV_EXCL_LINE: UntestablePath */
}
status =

@ -46,12 +46,12 @@ static void ares_evsys_epoll_destroy(ares_event_thread_t *e)
ares_evsys_epoll_t *ep = NULL;
if (e == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ep = e->ev_sys_data;
if (ep == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ep->epoll_fd != -1) {
@ -68,15 +68,15 @@ static ares_bool_t ares_evsys_epoll_init(ares_event_thread_t *e)
ep = ares_malloc_zero(sizeof(*ep));
if (ep == NULL) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: OutOfMemory */
}
e->ev_sys_data = ep;
ep->epoll_fd = epoll_create1(0);
if (ep->epoll_fd == -1) {
ares_evsys_epoll_destroy(e);
return ARES_FALSE;
ares_evsys_epoll_destroy(e); /* LCOV_EXCL_LINE: UntestablePath */
return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */
}
# ifdef FD_CLOEXEC
@ -85,8 +85,8 @@ static ares_bool_t ares_evsys_epoll_init(ares_event_thread_t *e)
e->ev_signal = ares_pipeevent_create(e);
if (e->ev_signal == NULL) {
ares_evsys_epoll_destroy(e);
return ARES_FALSE;
ares_evsys_epoll_destroy(e); /* LCOV_EXCL_LINE: UntestablePath */
return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */
}
return ARES_TRUE;
@ -108,7 +108,7 @@ static ares_bool_t ares_evsys_epoll_event_add(ares_event_t *event)
epev.events |= EPOLLOUT;
}
if (epoll_ctl(ep->epoll_fd, EPOLL_CTL_ADD, event->fd, &epev) != 0) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */
}
return ARES_TRUE;
}
@ -158,7 +158,7 @@ static size_t ares_evsys_epoll_wait(ares_event_thread_t *e,
rv = epoll_wait(ep->epoll_fd, events, (int)nevents,
(timeout_ms == 0) ? -1 : (int)timeout_ms);
if (rv < 0) {
return 0;
return 0; /* LCOV_EXCL_LINE: UntestablePath */
}
nevents = (size_t)rv;
@ -170,7 +170,7 @@ static size_t ares_evsys_epoll_wait(ares_event_thread_t *e,
ev = ares__htable_asvp_get_direct(e->ev_sock_handles,
(ares_socket_t)events[i].data.fd);
if (ev == NULL || ev->cb == NULL) {
continue;
continue; /* LCOV_EXCL_LINE: DefensiveCoding */
}
cnt++;

@ -37,7 +37,7 @@ static ares_bool_t ares_evsys_poll_init(ares_event_thread_t *e)
{
e->ev_signal = ares_pipeevent_create(e);
if (e->ev_signal == NULL) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */
}
return ARES_TRUE;
}
@ -78,7 +78,7 @@ static size_t ares_evsys_poll_wait(ares_event_thread_t *e,
if (fdlist != NULL && num_fds) {
pollfd = ares_malloc_zero(sizeof(*pollfd) * num_fds);
if (pollfd == NULL) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (i = 0; i < num_fds; i++) {
const ares_event_t *ev =
@ -111,7 +111,7 @@ static size_t ares_evsys_poll_wait(ares_event_thread_t *e,
ev = ares__htable_asvp_get_direct(e->ev_sock_handles, pollfd[i].fd);
if (ev == NULL || ev->cb == NULL) {
continue;
continue; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (pollfd[i].revents & (POLLERR | POLLHUP | POLLIN)) {

@ -45,7 +45,7 @@ static ares_bool_t ares_evsys_select_init(ares_event_thread_t *e)
{
e->ev_signal = ares_pipeevent_create(e);
if (e->ev_signal == NULL) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */
}
return ARES_TRUE;
}
@ -118,7 +118,7 @@ static size_t ares_evsys_select_wait(ares_event_thread_t *e,
ev = ares__htable_asvp_get_direct(e->ev_sock_handles, fdlist[i]);
if (ev == NULL || ev->cb == NULL) {
continue;
continue; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (FD_ISSET(fdlist[i], &read_fds)) {

@ -32,7 +32,7 @@ static void ares_event_destroy_cb(void *arg)
{
ares_event_t *event = arg;
if (event == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Unregister from the event thread if it was registered with one */
@ -90,7 +90,7 @@ ares_status_t ares_event_update(ares_event_t **event, ares_event_thread_t *e,
ares_event_t *ev = NULL;
if (e == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Callback must be specified if not a removal event. */
@ -124,12 +124,12 @@ ares_status_t ares_event_update(ares_event_t **event, ares_event_thread_t *e,
/* Allocate a new one */
ev = ares_malloc_zero(sizeof(*ev));
if (ev == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (ares__llist_insert_last(e->ev_updates, ev) == NULL) {
ares_free(ev);
return ARES_ENOMEM;
ares_free(ev); /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -158,7 +158,7 @@ ares_status_t ares_event_update(ares_event_t **event, ares_event_thread_t *e,
static void ares_event_signal(const ares_event_t *event)
{
if (event == NULL || event->signal_cb == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
event->signal_cb(event);
}
@ -166,7 +166,7 @@ static void ares_event_signal(const ares_event_t *event)
static void ares_event_thread_wake(const ares_event_thread_t *e)
{
if (e == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares_event_signal(e->ev_signal);
@ -345,7 +345,7 @@ void ares_event_thread_destroy(ares_channel_t *channel)
ares_event_thread_t *e = channel->sock_state_cb_data;
if (e == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares_event_thread_destroy_int(e);
@ -415,49 +415,51 @@ ares_status_t ares_event_thread_init(ares_channel_t *channel)
e = ares_malloc_zero(sizeof(*e));
if (e == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
e->mutex = ares__thread_mutex_create();
if (e->mutex == NULL) {
ares_event_thread_destroy_int(e);
return ARES_ENOMEM;
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
e->ev_updates = ares__llist_create(NULL);
if (e->ev_updates == NULL) {
ares_event_thread_destroy_int(e);
return ARES_ENOMEM;
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
e->ev_sock_handles = ares__htable_asvp_create(ares_event_destroy_cb);
if (e->ev_sock_handles == NULL) {
ares_event_thread_destroy_int(e);
return ARES_ENOMEM;
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
e->ev_cust_handles = ares__htable_vpvp_create(NULL, ares_event_destroy_cb);
if (e->ev_cust_handles == NULL) {
ares_event_thread_destroy_int(e);
return ARES_ENOMEM;
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
e->channel = channel;
e->isup = ARES_TRUE;
e->ev_sys = ares_event_fetch_sys(channel->evsys);
if (e->ev_sys == NULL) {
ares_event_thread_destroy_int(e);
return ARES_ENOTIMP;
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: UntestablePath */
return ARES_ENOTIMP; /* LCOV_EXCL_LINE: UntestablePath */
}
channel->sock_state_cb = ares_event_thread_sockstate_cb;
channel->sock_state_cb_data = e;
if (!e->ev_sys->init(e)) {
/* LCOV_EXCL_START: UntestablePath */
ares_event_thread_destroy_int(e);
channel->sock_state_cb = NULL;
channel->sock_state_cb_data = NULL;
return ARES_ESERVFAIL;
/* LCOV_EXCL_STOP */
}
/* Before starting the thread, process any possible events the initialization
@ -469,10 +471,12 @@ ares_status_t ares_event_thread_init(ares_channel_t *channel)
/* Start thread */
if (ares__thread_create(&e->thread, ares_event_thread, e) != ARES_SUCCESS) {
/* LCOV_EXCL_START: UntestablePath */
ares_event_thread_destroy_int(e);
channel->sock_state_cb = NULL;
channel->sock_state_cb_data = NULL;
return ARES_ESERVFAIL;
/* LCOV_EXCL_STOP */
}
return ARES_SUCCESS;

@ -60,7 +60,7 @@ static ares_pipeevent_t *ares_pipeevent_init(void)
{
ares_pipeevent_t *p = ares_malloc_zero(sizeof(*p));
if (p == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
p->filedes[0] = -1;
@ -68,8 +68,8 @@ static ares_pipeevent_t *ares_pipeevent_init(void)
# ifdef HAVE_PIPE2
if (pipe2(p->filedes, O_NONBLOCK | O_CLOEXEC) != 0) {
ares_pipeevent_destroy(p);
return NULL;
ares_pipeevent_destroy(p); /* LCOV_EXCL_LINE: UntestablePath */
return NULL; /* LCOV_EXCL_LINE: UntestablePath */
}
# else
if (pipe(p->filedes) != 0) {
@ -113,7 +113,7 @@ static void ares_pipeevent_signal(const ares_event_t *e)
const ares_pipeevent_t *p;
if (e == NULL || e->data == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
p = e->data;
@ -131,7 +131,7 @@ static void ares_pipeevent_cb(ares_event_thread_t *e, ares_socket_t fd,
(void)flags;
if (data == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
p = data;
@ -156,8 +156,8 @@ ares_event_t *ares_pipeevent_create(ares_event_thread_t *e)
p->filedes[0], p, ares_pipeevent_destroy_cb,
ares_pipeevent_signal);
if (status != ARES_SUCCESS) {
ares_pipeevent_destroy(p);
return NULL;
ares_pipeevent_destroy(p); /* LCOV_EXCL_LINE: DefensiveCoding */
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return event;

@ -91,8 +91,8 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
size_t enclen_temp = 0;
ares_status_t status;
if (alen < 0) {
return ARES_EBADRESP;
if (encoded == NULL || abuf == NULL || alen <= 0 || enclen == NULL) {
return ARES_EBADNAME;
}
status = ares__expand_name_validated(encoded, abuf, (size_t)alen, s,
@ -100,19 +100,3 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
*enclen = (long)enclen_temp;
return (int)status;
}
/* Like ares_expand_name_validated but returns EBADRESP in case of invalid
* input. */
ares_status_t ares__expand_name_for_response(const unsigned char *encoded,
const unsigned char *abuf,
size_t alen, char **s,
size_t *enclen,
ares_bool_t is_hostname)
{
ares_status_t status =
ares__expand_name_validated(encoded, abuf, alen, s, enclen, is_hostname);
if (status == ARES_EBADNAME) {
status = ARES_EBADRESP;
}
return status;
}

@ -100,7 +100,7 @@ int ares_expand_string(const unsigned char *encoded, const unsigned char *abuf,
ares_status_t status;
size_t temp_enclen = 0;
if (alen < 0) {
if (encoded == NULL || abuf == NULL || alen <= 0 || enclen == NULL) {
return ARES_EBADRESP;
}

@ -109,7 +109,7 @@ struct ares_addrinfo_cname *
struct ares_addrinfo_cname *last = *head;
if (tail == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (!last) {
@ -149,7 +149,7 @@ struct ares_addrinfo_node *
struct ares_addrinfo_node *last = *head;
if (tail == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (!last) {
@ -274,8 +274,8 @@ static ares_bool_t fake_addrinfo(const char *name, unsigned short port,
if (result) {
status = ares_append_ai_node(AF_INET, port, 0, &addr4, &ai->nodes);
if (status != ARES_SUCCESS) {
callback(arg, (int)status, 0, NULL);
return ARES_TRUE;
callback(arg, (int)status, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_TRUE; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -288,8 +288,8 @@ static ares_bool_t fake_addrinfo(const char *name, unsigned short port,
if (result) {
status = ares_append_ai_node(AF_INET6, port, 0, &addr6, &ai->nodes);
if (status != ARES_SUCCESS) {
callback(arg, (int)status, 0, NULL);
return ARES_TRUE;
callback(arg, (int)status, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_TRUE; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -301,9 +301,11 @@ static ares_bool_t fake_addrinfo(const char *name, unsigned short port,
if (hints->ai_flags & ARES_AI_CANONNAME) {
cname = ares__append_addrinfo_cname(&ai->cnames);
if (!cname) {
/* LCOV_EXCL_START: OutOfMemory */
ares_freeaddrinfo(ai);
callback(arg, ARES_ENOMEM, 0, NULL);
return ARES_TRUE;
/* LCOV_EXCL_STOP */
}
/* Duplicate the name, to avoid a constness violation. */
@ -368,7 +370,7 @@ ares_bool_t ares__is_localhost(const char *name)
size_t len;
if (name == NULL) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (strcmp(name, "localhost") == 0) {
@ -412,7 +414,7 @@ static ares_status_t file_lookup(struct host_query *hquery)
hquery->ai);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
@ -494,7 +496,7 @@ static void host_callback(void *arg, ares_status_t status, size_t timeouts,
if (status == ARES_SUCCESS) {
if (dnsrec == NULL) {
addinfostatus = ARES_EBADRESP;
addinfostatus = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
} else {
addinfostatus =
ares__parse_into_addrinfo(dnsrec, ARES_TRUE, hquery->port, hquery->ai);

@ -88,9 +88,11 @@ static void ares_gethostbyaddr_int(ares_channel_t *channel, const void *addr,
}
aquery->lookups = ares_strdup(channel->lookups);
if (aquery->lookups == NULL) {
/* LCOV_EXCL_START: OutOfMemory */
ares_free(aquery);
callback(arg, ARES_ENOMEM, 0, NULL);
return;
/* LCOV_EXCL_STOP */
}
aquery->channel = channel;
if (family == AF_INET) {
@ -130,8 +132,8 @@ static void next_lookup(struct addr_query *aquery)
case 'b':
name = ares_dns_addr_to_ptr(&aquery->addr);
if (name == NULL) {
end_aquery(aquery, ARES_ENOMEM, NULL);
return;
end_aquery(aquery, ARES_ENOMEM, NULL); /* LCOV_EXCL_LINE: OutOfMemory */
return; /* LCOV_EXCL_LINE: OutOfMemory */
}
aquery->remaining_lookups = p + 1;
ares_query_dnsrec(aquery->channel, name, ARES_CLASS_IN,
@ -223,7 +225,7 @@ static ares_status_t file_lookup(ares_channel_t *channel,
status = ares__hosts_entry_to_hostent(entry, addr->family, host);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_SUCCESS;

@ -248,18 +248,18 @@ static ares_status_t ares__hostent_localhost(const char *name, int family,
ai = ares_malloc_zero(sizeof(*ai));
if (ai == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__addrinfo_localhost(name, 0, &hints, ai);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__addrinfo2hostent(ai, family, host_out);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
done:
@ -298,7 +298,7 @@ static ares_status_t ares_gethostbyname_file_int(ares_channel_t *channel,
status = ares__hosts_entry_to_hostent(entry, family, host);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
done:

@ -117,7 +117,7 @@ static int server_sort_cb(const void *data1, const void *data2)
static void server_destroy_cb(void *data)
{
if (data == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__destroy_server(data);
}
@ -162,7 +162,7 @@ static ares_status_t init_by_defaults(ares_channel_t *channel)
rc = ares__sconfig_append(&sconfig, &addr, 0, 0, NULL);
if (rc != ARES_SUCCESS) {
goto error;
goto error; /* LCOV_EXCL_LINE: OutOfMemory */
}
rc = ares__servers_update(channel, sconfig, ARES_FALSE);
@ -196,8 +196,8 @@ static ares_status_t init_by_defaults(ares_channel_t *channel)
hostname = ares_malloc(len);
if (!hostname) {
rc = ARES_ENOMEM;
goto error;
rc = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto error; /* LCOV_EXCL_LINE: OutOfMemory */
}
do {
@ -209,8 +209,8 @@ static ares_status_t init_by_defaults(ares_channel_t *channel)
lenv *= 2;
p = ares_realloc(hostname, len);
if (!p) {
rc = ARES_ENOMEM;
goto error;
rc = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto error; /* LCOV_EXCL_LINE: OutOfMemory */
}
hostname = p;
continue;
@ -228,13 +228,13 @@ static ares_status_t init_by_defaults(ares_channel_t *channel)
/* a dot was found */
channel->domains = ares_malloc(sizeof(char *));
if (!channel->domains) {
rc = ARES_ENOMEM;
goto error;
rc = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto error; /* LCOV_EXCL_LINE: OutOfMemory */
}
channel->domains[0] = ares_strdup(dot + 1);
if (!channel->domains[0]) {
rc = ARES_ENOMEM;
goto error;
rc = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto error; /* LCOV_EXCL_LINE: OutOfMemory */
}
channel->ndomains = 1;
}
@ -248,7 +248,7 @@ static ares_status_t init_by_defaults(ares_channel_t *channel)
if (!channel->lookups) {
channel->lookups = ares_strdup("fb");
if (!channel->lookups) {
rc = ARES_ENOMEM;
rc = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -350,7 +350,7 @@ int ares_init_options(ares_channel_t **channelptr,
status = ares__qcache_create(channel->rand_state, channel->qcache_max_ttl,
&channel->qcache);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -379,7 +379,7 @@ int ares_init_options(ares_channel_t **channelptr,
status = ares_event_thread_init(channel);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: UntestablePath */
}
/* Initialize monitor for configuration changes. In some rare cases,
@ -387,7 +387,7 @@ int ares_init_options(ares_channel_t **channelptr,
e = channel->sock_state_cb_data;
status = ares_event_configchg_init(&e->configchg, e);
if (status != ARES_SUCCESS && status != ARES_ENOTIMP) {
goto done;
goto done; /* LCOV_EXCL_LINE: UntestablePath */
}
status = ARES_SUCCESS;
}
@ -459,9 +459,11 @@ ares_status_t ares_reinit(ares_channel_t *channel)
status =
ares__thread_create(&channel->reinit_thread, ares_reinit_thread, channel);
if (status != ARES_SUCCESS) {
/* LCOV_EXCL_START: UntestablePath */
ares__channel_lock(channel);
channel->reinit_pending = ARES_FALSE;
ares__channel_unlock(channel);
/* LCOV_EXCL_STOP */
}
} else {
/* Threading support not available, call directly */
@ -534,18 +536,22 @@ int ares_dup(ares_channel_t **dest, const ares_channel_t *src)
if (optmask & ARES_OPT_SERVERS) {
char *csv = ares_get_servers_csv(src);
if (csv == NULL) {
/* LCOV_EXCL_START: OutOfMemory */
ares_destroy(*dest);
*dest = NULL;
rc = ARES_ENOMEM;
goto done;
/* LCOV_EXCL_STOP */
}
rc = (ares_status_t)ares_set_servers_ports_csv(*dest, csv);
ares_free_string(csv);
if (rc != ARES_SUCCESS) {
/* LCOV_EXCL_START: OutOfMemory */
ares_destroy(*dest);
*dest = NULL;
goto done;
/* LCOV_EXCL_STOP */
}
}

@ -249,7 +249,7 @@ static ares_status_t ares__init_options_servers(ares_channel_t *channel,
status = ares_in_addr_to_server_config_llist(servers, nservers, &slist);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__servers_update(channel, slist, ARES_TRUE);
@ -266,12 +266,12 @@ ares_status_t ares__init_by_options(ares_channel_t *channel,
size_t i;
if (channel == NULL) {
return ARES_ENODATA;
return ARES_ENODATA; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (options == NULL) {
if (optmask != 0) {
return ARES_ENODATA;
return ARES_ENODATA; /* LCOV_EXCL_LINE: DefensiveCoding */
}
return ARES_SUCCESS;
}
@ -389,13 +389,13 @@ ares_status_t ares__init_by_options(ares_channel_t *channel,
channel->domains =
ares_malloc_zero((size_t)options->ndomains * sizeof(char *));
if (!channel->domains) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
channel->ndomains = (size_t)options->ndomains;
for (i = 0; i < (size_t)options->ndomains; i++) {
channel->domains[i] = ares_strdup(options->domains[i]);
if (!channel->domains[i]) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -407,7 +407,7 @@ ares_status_t ares__init_by_options(ares_channel_t *channel,
} else {
channel->lookups = ares_strdup(options->lookups);
if (!channel->lookups) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -418,7 +418,7 @@ ares_status_t ares__init_by_options(ares_channel_t *channel,
channel->sortlist =
ares_malloc((size_t)options->nsort * sizeof(struct apattern));
if (!channel->sortlist) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (i = 0; i < (size_t)options->nsort; i++) {
channel->sortlist[i] = options->sortlist[i];
@ -432,7 +432,7 @@ ares_status_t ares__init_by_options(ares_channel_t *channel,
} else {
channel->resolvconf_path = ares_strdup(options->resolvconf_path);
if (channel->resolvconf_path == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -444,7 +444,7 @@ ares_status_t ares__init_by_options(ares_channel_t *channel,
} else {
channel->hosts_path = ares_strdup(options->hosts_path);
if (channel->hosts_path == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -475,7 +475,7 @@ ares_status_t ares__init_by_options(ares_channel_t *channel,
status = ares__init_options_servers(channel, options->servers,
(size_t)options->nservers);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}

@ -85,7 +85,7 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
if (host != NULL) {
status = ares__addrinfo2hostent(&ai, AF_INET, host);
if (status != ARES_SUCCESS && status != ARES_ENODATA) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: DefensiveCoding */
}
}

@ -87,7 +87,7 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
if (host != NULL) {
status = ares__addrinfo2hostent(&ai, AF_INET6, host);
if (status != ARES_SUCCESS && status != ARES_ENODATA) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: DefensiveCoding */
}
}

@ -66,8 +66,8 @@ int ares_parse_caa_reply(const unsigned char *abuf, int alen_int,
if (rr == NULL) {
/* Shouldn't be possible */
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* XXX: Why do we allow Chaos class? */
@ -84,8 +84,8 @@ int ares_parse_caa_reply(const unsigned char *abuf, int alen_int,
/* Allocate storage for this CAA answer appending it to the list */
caa_curr = ares_malloc_data(ARES_DATATYPE_CAA_REPLY);
if (caa_curr == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Link in the record */
@ -100,8 +100,8 @@ int ares_parse_caa_reply(const unsigned char *abuf, int alen_int,
caa_curr->property =
(unsigned char *)ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_CAA_TAG));
if (caa_curr->property == NULL) {
status = ARES_ENOMEM;
break;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
break; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* RFC6844 says this can only be ascii, so not sure why we're recording a
* length */
@ -109,15 +109,15 @@ int ares_parse_caa_reply(const unsigned char *abuf, int alen_int,
ptr = ares_dns_rr_get_bin(rr, ARES_RR_CAA_VALUE, &ptr_len);
if (ptr == NULL) {
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Wants NULL termination for some reason */
caa_curr->value = ares_malloc(ptr_len + 1);
if (caa_curr->value == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
memcpy(caa_curr->value, ptr, ptr_len);
caa_curr->value[ptr_len] = 0;

@ -64,8 +64,8 @@ int ares_parse_mx_reply(const unsigned char *abuf, int alen_int,
if (rr == NULL) {
/* Shouldn't be possible */
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN ||
@ -76,8 +76,8 @@ int ares_parse_mx_reply(const unsigned char *abuf, int alen_int,
/* Allocate storage for this MX answer appending it to the list */
mx_curr = ares_malloc_data(ARES_DATATYPE_MX_REPLY);
if (mx_curr == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Link in the record */
@ -92,8 +92,8 @@ int ares_parse_mx_reply(const unsigned char *abuf, int alen_int,
mx_curr->host = ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_MX_EXCHANGE));
if (mx_curr->host == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}

@ -63,8 +63,8 @@ int ares_parse_naptr_reply(const unsigned char *abuf, int alen_int,
if (rr == NULL) {
/* Shouldn't be possible */
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN ||
@ -75,8 +75,8 @@ int ares_parse_naptr_reply(const unsigned char *abuf, int alen_int,
/* Allocate storage for this NAPTR answer appending it to the list */
naptr_curr = ares_malloc_data(ARES_DATATYPE_NAPTR_REPLY);
if (naptr_curr == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Link in the record */
@ -94,28 +94,28 @@ int ares_parse_naptr_reply(const unsigned char *abuf, int alen_int,
naptr_curr->flags = (unsigned char *)ares_strdup(
ares_dns_rr_get_str(rr, ARES_RR_NAPTR_FLAGS));
if (naptr_curr->flags == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* XXX: Why is this unsigned char * ? */
naptr_curr->service = (unsigned char *)ares_strdup(
ares_dns_rr_get_str(rr, ARES_RR_NAPTR_SERVICES));
if (naptr_curr->service == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* XXX: Why is this unsigned char * ? */
naptr_curr->regexp = (unsigned char *)ares_strdup(
ares_dns_rr_get_str(rr, ARES_RR_NAPTR_REGEXP));
if (naptr_curr->regexp == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
naptr_curr->replacement =
ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_NAPTR_REPLACEMENT));
if (naptr_curr->replacement == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}

@ -73,16 +73,16 @@ int ares_parse_ns_reply(const unsigned char *abuf, int alen_int,
/* Response structure */
hostent = ares_malloc(sizeof(*hostent));
if (hostent == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
memset(hostent, 0, sizeof(*hostent));
hostent->h_addr_list = ares_malloc(sizeof(*hostent->h_addr_list));
if (hostent->h_addr_list == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
hostent->h_addr_list[0] = NULL;
hostent->h_addrtype = AF_INET;
@ -91,19 +91,19 @@ int ares_parse_ns_reply(const unsigned char *abuf, int alen_int,
/* Fill in hostname */
status = ares_dns_record_query_get(dnsrec, 0, &hostname, NULL, NULL);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
hostent->h_name = ares_strdup(hostname);
if (hostent->h_name == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Preallocate the maximum number + 1 */
hostent->h_aliases = ares_malloc((ancount + 1) * sizeof(*hostent->h_aliases));
if (hostent->h_aliases == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
memset(hostent->h_aliases, 0, (ancount + 1) * sizeof(*hostent->h_aliases));
@ -113,8 +113,8 @@ int ares_parse_ns_reply(const unsigned char *abuf, int alen_int,
if (rr == NULL) {
/* Shouldn't be possible */
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN ||
@ -124,8 +124,8 @@ int ares_parse_ns_reply(const unsigned char *abuf, int alen_int,
hostname = ares_dns_rr_get_str(rr, ARES_RR_NS_NSDNAME);
if (hostname == NULL) {
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
hostent->h_aliases[nscount] = ares_strdup(hostname);

@ -105,8 +105,8 @@ ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec,
if (rr == NULL) {
/* Shouldn't be possible */
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN) {
@ -117,8 +117,8 @@ ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec,
if (ares_dns_rr_get_type(rr) == ARES_REC_TYPE_CNAME) {
ptrname = ares_dns_rr_get_str(rr, ARES_RR_CNAME_CNAME);
if (ptrname == NULL) {
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
}
@ -145,8 +145,8 @@ ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec,
/* Save most recent PTR record as the hostname */
hostname = ares_dns_rr_get_str(rr, ARES_RR_PTR_DNAME);
if (hostname == NULL) {
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Append as an alias */
@ -168,8 +168,8 @@ ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec,
/* Fill in hostname */
hostent->h_name = ares_strdup(hostname);
if (hostent->h_name == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
done:

@ -62,8 +62,8 @@ int ares_parse_soa_reply(const unsigned char *abuf, int alen_int,
if (rr == NULL) {
/* Shouldn't be possible */
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN ||
@ -74,8 +74,8 @@ int ares_parse_soa_reply(const unsigned char *abuf, int alen_int,
/* allocate result struct */
soa = ares_malloc_data(ARES_DATATYPE_SOA_REPLY);
if (soa == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
soa->serial = ares_dns_rr_get_u32(rr, ARES_RR_SOA_SERIAL);
@ -85,13 +85,13 @@ int ares_parse_soa_reply(const unsigned char *abuf, int alen_int,
soa->minttl = ares_dns_rr_get_u32(rr, ARES_RR_SOA_MINIMUM);
soa->nsname = ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_SOA_MNAME));
if (soa->nsname == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
soa->hostmaster = ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_SOA_RNAME));
if (soa->hostmaster == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
break;
}

@ -64,8 +64,8 @@ int ares_parse_srv_reply(const unsigned char *abuf, int alen_int,
if (rr == NULL) {
/* Shouldn't be possible */
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN ||
@ -76,8 +76,8 @@ int ares_parse_srv_reply(const unsigned char *abuf, int alen_int,
/* Allocate storage for this SRV answer appending it to the list */
srv_curr = ares_malloc_data(ARES_DATATYPE_SRV_REPLY);
if (srv_curr == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Link in the record */
@ -96,8 +96,8 @@ int ares_parse_srv_reply(const unsigned char *abuf, int alen_int,
srv_curr->host = ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_SRV_TARGET));
if (srv_curr->host == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}

@ -59,8 +59,8 @@ static int ares__parse_txt_reply(const unsigned char *abuf, size_t alen,
if (rr == NULL) {
/* Shouldn't be possible */
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* XXX: Why Chaos? */
@ -74,8 +74,8 @@ static int ares__parse_txt_reply(const unsigned char *abuf, size_t alen,
txt_curr =
ares_malloc_data(ex ? ARES_DATATYPE_TXT_EXT : ARES_DATATYPE_TXT_REPLY);
if (txt_curr == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Link in the record */
@ -95,8 +95,8 @@ static int ares__parse_txt_reply(const unsigned char *abuf, size_t alen,
txt_curr->txt = ares_malloc(ptr_len + 1);
if (txt_curr->txt == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
memcpy(txt_curr->txt, ptr, ptr_len);
txt_curr->txt[ptr_len] = 0;

@ -64,8 +64,8 @@ int ares_parse_uri_reply(const unsigned char *abuf, int alen_int,
if (rr == NULL) {
/* Shouldn't be possible */
status = ARES_EBADRESP;
goto done;
status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */
goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN ||
@ -76,8 +76,8 @@ int ares_parse_uri_reply(const unsigned char *abuf, int alen_int,
/* Allocate storage for this URI answer appending it to the list */
uri_curr = ares_malloc_data(ARES_DATATYPE_URI_REPLY);
if (uri_curr == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Link in the record */

@ -419,11 +419,6 @@ ares_status_t ares__expand_name_validated(const unsigned char *encoded,
const unsigned char *abuf,
size_t alen, char **s, size_t *enclen,
ares_bool_t is_hostname);
ares_status_t ares__expand_name_for_response(const unsigned char *encoded,
const unsigned char *abuf,
size_t alen, char **s,
size_t *enclen,
ares_bool_t is_hostname);
ares_status_t ares_expand_string_ex(const unsigned char *encoded,
const unsigned char *abuf, size_t alen,
unsigned char **s, size_t *enclen);

@ -87,19 +87,19 @@ static void invoke_server_state_cb(const struct server_state *server,
buf = ares__buf_create();
if (buf == NULL) {
return;
return; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares_get_server_addr(server, buf);
if (status != ARES_SUCCESS) {
ares__buf_destroy(buf);
return;
ares__buf_destroy(buf); /* LCOV_EXCL_LINE: OutOfMemory */
return; /* LCOV_EXCL_LINE: OutOfMemory */
}
server_string = ares__buf_finish_str(buf, NULL);
buf = NULL;
if (server_string == NULL) {
return;
return; /* LCOV_EXCL_LINE: OutOfMemory */
}
channel->server_state_cb(server_string, success, flags,
@ -116,7 +116,7 @@ static void server_increment_failures(struct server_state *server,
node = ares__slist_node_find(channel->servers, server);
if (node == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
server->consec_failures++;
@ -138,7 +138,7 @@ static void server_set_good(struct server_state *server, ares_bool_t used_tcp)
node = ares__slist_node_find(channel->servers, server);
if (node == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (server->consec_failures > 0) {
@ -195,7 +195,7 @@ static void processfds(ares_channel_t *channel, fd_set *read_fds,
ares_timeval_t now;
if (channel == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__channel_lock(channel);
@ -412,7 +412,7 @@ static int socket_list_append(ares_socket_t **socketlist, ares_socket_t fd,
ares_socket_t *new_list =
ares_realloc(socketlist, new_alloc * sizeof(*new_list));
if (new_list == NULL) {
return 0;
return 0; /* LCOV_EXCL_LINE: OutOfMemory */
}
*alloc_cnt = new_alloc;
*socketlist = new_list;
@ -432,7 +432,7 @@ static ares_socket_t *channel_socket_list(const ares_channel_t *channel,
*num = 0;
if (out == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (snode = ares__slist_node_first(channel->servers); snode != NULL;
@ -449,7 +449,7 @@ static ares_socket_t *channel_socket_list(const ares_channel_t *channel,
}
if (!socket_list_append(&out, conn->fd, &alloc_cnt, num)) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
}
@ -652,7 +652,7 @@ static ares_status_t rewrite_without_edns(ares_dns_record_t *qdnsrec,
/* Rewrite the DNS message */
status = ares_dns_write(qdnsrec, &msg, &msglen);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
ares_free(query->qbuf);
@ -893,7 +893,7 @@ static struct server_state *ares__failover_server(ares_channel_t *channel)
/* Defensive code against no servers being available on the channel. */
if (first_server == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* If no servers have failures, then prefer the first server in the list. */
@ -939,7 +939,7 @@ static ares_status_t ares__append_tcpbuf(struct server_state *server,
status = ares__buf_append_be16(server->tcp_send, (unsigned short)query->qlen);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ares__buf_append(server->tcp_send, query->qbuf, query->qlen);
}
@ -952,7 +952,7 @@ static size_t ares__calc_query_timeout(const struct query *query)
size_t num_servers = ares__slist_len(channel->servers);
if (num_servers == 0) {
return 0;
return 0; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* For each trip through the entire server list, we want to double the
@ -1132,6 +1132,7 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now)
query->node_queries_by_timeout =
ares__slist_insert(channel->queries_by_timeout, query);
if (!query->node_queries_by_timeout) {
/* LCOV_EXCL_START: OutOfMemory */
end_query(channel, query, ARES_ENOMEM, NULL);
/* Only safe to kill connection if it was new, otherwise it should be
* cleaned up by another process later */
@ -1139,6 +1140,7 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now)
ares__close_connection(conn);
}
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
/* Keep track of queries bucketed by connection, so we can process errors
@ -1148,6 +1150,7 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now)
ares__llist_insert_last(conn->queries_to_conn, query);
if (query->node_queries_to_conn == NULL) {
/* LCOV_EXCL_START: OutOfMemory */
end_query(channel, query, ARES_ENOMEM, NULL);
/* Only safe to kill connection if it was new, otherwise it should be
* cleaned up by another process later */
@ -1155,6 +1158,7 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now)
ares__close_connection(conn);
}
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
query->conn = conn;

@ -48,7 +48,7 @@ static char *ares__qcache_calc_key(const ares_dns_record_t *dnsrec)
ares_dns_flags_t flags;
if (dnsrec == NULL || buf == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Format is OPCODE|FLAGS[|QTYPE1|QCLASS1|QNAME1]... */
@ -56,12 +56,12 @@ static char *ares__qcache_calc_key(const ares_dns_record_t *dnsrec)
status = ares__buf_append_str(
buf, ares_dns_opcode_tostr(ares_dns_record_get_opcode(dnsrec)));
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_byte(buf, '|');
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
flags = ares_dns_record_get_flags(dnsrec);
@ -69,13 +69,13 @@ static char *ares__qcache_calc_key(const ares_dns_record_t *dnsrec)
if (flags & ARES_FLAG_RD) {
status = ares__buf_append_str(buf, "rd");
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
if (flags & ARES_FLAG_CD) {
status = ares__buf_append_str(buf, "cd");
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -87,32 +87,32 @@ static char *ares__qcache_calc_key(const ares_dns_record_t *dnsrec)
status = ares_dns_record_query_get(dnsrec, i, &name, &qtype, &qclass);
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: DefensiveCoding */
}
status = ares__buf_append_byte(buf, '|');
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_str(buf, ares_dns_rec_type_tostr(qtype));
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_byte(buf, '|');
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_str(buf, ares_dns_class_tostr(qclass));
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_byte(buf, '|');
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* On queries, a '.' may be appended to the name to indicate an explicit
@ -125,15 +125,17 @@ static char *ares__qcache_calc_key(const ares_dns_record_t *dnsrec)
status = ares__buf_append(buf, (const unsigned char *)name, name_len);
if (status != ARES_SUCCESS) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
return ares__buf_finish_str(buf, NULL);
/* LCOV_EXCL_START: OutOfMemory */
fail:
ares__buf_destroy(buf);
return NULL;
/* LCOV_EXCL_STOP */
}
static void ares__qcache_expire(ares__qcache_t *cache,
@ -194,7 +196,7 @@ static void ares__qcache_entry_destroy_cb(void *arg)
{
ares__qcache_entry_t *entry = arg;
if (entry == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares_free(entry->key);
@ -211,21 +213,21 @@ ares_status_t ares__qcache_create(ares_rand_state *rand_state,
cache = ares_malloc_zero(sizeof(*cache));
if (cache == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
cache->cache = ares__htable_strvp_create(NULL);
if (cache->cache == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
cache->expire = ares__slist_create(rand_state, ares__qcache_entry_sort_cb,
ares__qcache_entry_destroy_cb);
if (cache->expire == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
cache->max_ttl = max_ttl;
@ -361,7 +363,7 @@ static ares_status_t ares__qcache_insert(ares__qcache_t *qcache,
entry = ares_malloc_zero(sizeof(*entry));
if (entry == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
entry->dnsrec = dnsrec;
@ -374,19 +376,20 @@ static ares_status_t ares__qcache_insert(ares__qcache_t *qcache,
* want to cache it */
entry->key = ares__qcache_calc_key_frombuf(qbuf, qlen);
if (entry->key == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (!ares__htable_strvp_insert(qcache->cache, entry->key, entry)) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (ares__slist_insert(qcache->expire, entry) == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_SUCCESS;
/* LCOV_EXCL_START: OutOfMemory */
fail:
if (entry != NULL && entry->key != NULL) {
ares__htable_strvp_remove(qcache->cache, entry->key);
@ -394,6 +397,7 @@ fail:
ares_free(entry);
}
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
ares_status_t ares_qcache_fetch(ares_channel_t *channel,
@ -417,8 +421,8 @@ ares_status_t ares_qcache_fetch(ares_channel_t *channel,
key = ares__qcache_calc_key(dnsrec);
if (key == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
entry = ares__htable_strvp_get_direct(channel->qcache->cache, key);

@ -76,11 +76,13 @@ static ares_status_t ares_query_int(ares_channel_t *channel, const char *name,
ares_query_dnsrec_arg_t *qquery = NULL;
if (channel == NULL || name == NULL || callback == NULL) {
/* LCOV_EXCL_START: DefensiveCoding */
status = ARES_EFORMERR;
if (callback != NULL) {
callback(arg, status, 0, NULL);
}
return status;
/* LCOV_EXCL_STOP */
}
if (!(channel->flags & ARES_FLAG_NORECURSE)) {
@ -91,16 +93,18 @@ static ares_status_t ares_query_int(ares_channel_t *channel, const char *name,
&dnsrec, name, dnsclass, type, 0, flags,
(size_t)(channel->flags & ARES_FLAG_EDNS) ? channel->ednspsz : 0);
if (status != ARES_SUCCESS) {
callback(arg, status, 0, NULL);
return status;
callback(arg, status, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
qquery = ares_malloc(sizeof(*qquery));
if (qquery == NULL) {
/* LCOV_EXCL_START: OutOfMemory */
status = ARES_ENOMEM;
callback(arg, status, 0, NULL);
ares_dns_record_destroy(dnsrec);
return status;
/* LCOV_EXCL_STOP */
}
qquery->callback = callback;
@ -142,8 +146,8 @@ void ares_query(ares_channel_t *channel, const char *name, int dnsclass,
carg = ares__dnsrec_convert_arg(callback, arg);
if (carg == NULL) {
callback(arg, ARES_ENOMEM, 0, NULL, 0);
return;
callback(arg, ARES_ENOMEM, 0, NULL, 0); /* LCOV_EXCL_LINE: OutOfMemory */
return; /* LCOV_EXCL_LINE: OutOfMemory */
}
ares_query_dnsrec(channel, name, (ares_dns_class_t)dnsclass,

@ -56,17 +56,20 @@ typedef struct ares_rand_rc4 {
static unsigned int ares_u32_from_ptr(void *addr)
{
/* LCOV_EXCL_START: FallbackCode */
if (sizeof(void *) == 8) {
return (unsigned int)((((ares_uint64_t)addr >> 32) & 0xFFFFFFFF) |
((ares_uint64_t)addr & 0xFFFFFFFF));
}
return (unsigned int)((size_t)addr & 0xFFFFFFFF);
/* LCOV_EXCL_STOP */
}
/* initialize an rc4 key as the last possible fallback. */
static void ares_rc4_generate_key(ares_rand_rc4 *rc4_state, unsigned char *key,
size_t key_len)
{
/* LCOV_EXCL_START: FallbackCode */
size_t i;
size_t len = 0;
unsigned int data;
@ -99,10 +102,12 @@ static void ares_rc4_generate_key(ares_rand_rc4 *rc4_state, unsigned char *key,
for (i = len; i < key_len; i++) {
key[i] = (unsigned char)(rand() % 256); /* LCOV_EXCL_LINE */
}
/* LCOV_EXCL_STOP */
}
static void ares_rc4_init(ares_rand_rc4 *rc4_state)
{
/* LCOV_EXCL_START: FallbackCode */
unsigned char key[ARES_RC4_KEY_LEN];
size_t i;
size_t j;
@ -120,6 +125,7 @@ static void ares_rc4_init(ares_rand_rc4 *rc4_state)
rc4_state->i = 0;
rc4_state->j = 0;
/* LCOV_EXCL_STOP */
}
/* Just outputs the key schedule, no need to XOR with any data since we have
@ -127,6 +133,7 @@ static void ares_rc4_init(ares_rand_rc4 *rc4_state)
static void ares_rc4_prng(ares_rand_rc4 *rc4_state, unsigned char *buf,
size_t len)
{
/* LCOV_EXCL_START: FallbackCode */
unsigned char *S = rc4_state->S;
size_t i = rc4_state->i;
size_t j = rc4_state->j;
@ -142,6 +149,7 @@ static void ares_rc4_prng(ares_rand_rc4 *rc4_state, unsigned char *buf,
rc4_state->i = i;
rc4_state->j = j;
/* LCOV_EXCL_STOP */
}
struct ares_rand_state {
@ -187,6 +195,7 @@ static ares_bool_t ares__init_rand_engine(ares_rand_state *state)
#endif
#if defined(CARES_RANDOM_FILE)
/* LCOV_EXCL_START: FallbackCode */
if (!(state->bad_backends & ARES_RAND_FILE)) {
state->type = ARES_RAND_FILE;
state->state.rand_file = fopen(CARES_RANDOM_FILE, "rb");
@ -195,14 +204,18 @@ static ares_bool_t ares__init_rand_engine(ares_rand_state *state)
return ARES_TRUE;
}
}
/* LCOV_EXCL_STOP */
/* Fall-Thru on failure to RC4 */
#endif
/* LCOV_EXCL_START: FallbackCode */
state->type = ARES_RAND_RC4;
ares_rc4_init(&state->state.rc4);
/* LCOV_EXCL_STOP */
/* Currently cannot fail */
return ARES_TRUE;
return ARES_TRUE; /* LCOV_EXCL_LINE: UntestablePath */
}
ares_rand_state *ares__init_rand_state(void)
@ -215,8 +228,8 @@ ares_rand_state *ares__init_rand_state(void)
}
if (!ares__init_rand_engine(state)) {
ares_free(state);
return NULL;
ares_free(state); /* LCOV_EXCL_LINE: UntestablePath */
return NULL; /* LCOV_EXCL_LINE: UntestablePath */
}
return state;
@ -225,24 +238,28 @@ ares_rand_state *ares__init_rand_state(void)
static void ares__clear_rand_state(ares_rand_state *state)
{
if (!state) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
switch (state->type) {
case ARES_RAND_OS:
break;
/* LCOV_EXCL_START: FallbackCode */
case ARES_RAND_FILE:
fclose(state->state.rand_file);
break;
case ARES_RAND_RC4:
break;
/* LCOV_EXCL_STOP */
}
}
static void ares__reinit_rand(ares_rand_state *state)
{
/* LCOV_EXCL_START: UntestablePath */
ares__clear_rand_state(state);
ares__init_rand_engine(state);
/* LCOV_EXCL_STOP */
}
void ares__destroy_rand_state(ares_rand_state *state)
@ -296,6 +313,8 @@ static void ares__rand_bytes_fetch(ares_rand_state *state, unsigned char *buf,
break;
#endif
/* LCOV_EXCL_START: FallbackCode */
case ARES_RAND_FILE:
while (1) {
size_t rv = fread(buf + bytes_read, 1, len - bytes_read,
@ -314,11 +333,14 @@ static void ares__rand_bytes_fetch(ares_rand_state *state, unsigned char *buf,
case ARES_RAND_RC4:
ares_rc4_prng(&state->state.rc4, buf, len);
return;
/* LCOV_EXCL_STOP */
}
/* If we didn't return before we got here, that means we had a critical rand
* failure and need to reinitialized */
ares__reinit_rand(state);
ares__reinit_rand(state); /* LCOV_EXCL_LINE: UntestablePath */
}
}

@ -57,7 +57,7 @@ struct search_query {
static void squery_free(struct search_query *squery)
{
if (squery == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__strsplit_free(squery->names, squery->names_cnt);
ares_dns_record_destroy(squery->dnsrec);
@ -87,7 +87,7 @@ static ares_status_t ares_search_next(ares_channel_t *channel,
/* Misuse check */
if (squery->next_name_idx >= squery->names_cnt) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
status = ares_dns_record_query_set_name(
@ -200,8 +200,8 @@ ares_status_t ares__search_name_list(const ares_channel_t *channel,
list_len = 1;
list = ares_malloc_zero(sizeof(*list) * list_len);
if (list == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
list[0] = alias;
alias = NULL;
@ -215,12 +215,12 @@ ares_status_t ares__search_name_list(const ares_channel_t *channel,
list_len = 1;
list = ares_malloc_zero(sizeof(*list) * list_len);
if (list == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
list[0] = ares_strdup(name);
if (list[0] == NULL) {
status = ARES_ENOMEM;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
} else {
status = ARES_SUCCESS;
}
@ -322,8 +322,8 @@ static ares_status_t ares_search_int(ares_channel_t *channel,
*/
squery = ares_malloc_zero(sizeof(*squery));
if (squery == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
squery->channel = channel;
@ -331,8 +331,8 @@ static ares_status_t ares_search_int(ares_channel_t *channel,
/* Duplicate DNS record since, name will need to be rewritten */
squery->dnsrec = ares_dns_record_duplicate(dnsrec);
if (squery->dnsrec == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
squery->callback = callback;
@ -456,7 +456,7 @@ ares_status_t ares_search_dnsrec(ares_channel_t *channel,
ares_status_t status;
if (channel == NULL || dnsrec == NULL || callback == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__channel_lock(channel);
@ -498,7 +498,7 @@ ares_status_t ares__lookup_hostaliases(const ares_channel_t *channel,
ares__llist_node_t *node;
if (channel == NULL || name == NULL || alias == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
*alias = NULL;
@ -521,8 +521,8 @@ ares_status_t ares__lookup_hostaliases(const ares_channel_t *channel,
buf = ares__buf_create();
if (buf == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_load_file(hostaliases, buf);
@ -581,8 +581,8 @@ ares_status_t ares__lookup_hostaliases(const ares_channel_t *channel,
*alias = ares_strdup(fqdn);
if (*alias == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* Good! */

@ -77,8 +77,8 @@ static ares_status_t ares_send_dnsrec_int(ares_channel_t *channel,
/* Allocate space for query and allocated fields. */
query = ares_malloc(sizeof(struct query));
if (!query) {
callback(arg, ARES_ENOMEM, 0, NULL);
return ARES_ENOMEM;
callback(arg, ARES_ENOMEM, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
memset(query, 0, sizeof(*query));
@ -121,18 +121,22 @@ static ares_status_t ares_send_dnsrec_int(ares_channel_t *channel,
query->node_all_queries =
ares__llist_insert_last(channel->all_queries, query);
if (query->node_all_queries == NULL) {
/* LCOV_EXCL_START: OutOfMemory */
callback(arg, ARES_ENOMEM, 0, NULL);
ares__free_query(query);
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
/* Keep track of queries bucketed by qid, so we can process DNS
* responses quickly.
*/
if (!ares__htable_szvp_insert(channel->queries_by_qid, query->qid, query)) {
/* LCOV_EXCL_START: OutOfMemory */
callback(arg, ARES_ENOMEM, 0, NULL);
ares__free_query(query);
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
/* Perform the first query action. */
@ -152,7 +156,7 @@ ares_status_t ares_send_dnsrec(ares_channel_t *channel,
ares_status_t status;
if (channel == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__channel_lock(channel);
@ -189,10 +193,12 @@ void ares_send(ares_channel_t *channel, const unsigned char *qbuf, int qlen,
carg = ares__dnsrec_convert_arg(callback, arg);
if (carg == NULL) {
/* LCOV_EXCL_START: OutOfMemory */
status = ARES_ENOMEM;
ares_dns_record_destroy(dnsrec);
callback(arg, (int)status, 0, NULL, 0);
return;
/* LCOV_EXCL_STOP */
}
ares_send_dnsrec(channel, dnsrec, ares__dnsrec_convert_cb, carg, NULL);

@ -56,7 +56,7 @@ char *ares_strdup(const char *s1)
/* Don't see how this is possible */
if (len == SIZE_MAX) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
out = ares_malloc(len + 1);
@ -77,7 +77,7 @@ size_t ares_strcpy(char *dest, const char *src, size_t dest_size)
size_t len = 0;
if (dest == NULL || dest_size == 0) {
return 0;
return 0; /* LCOV_EXCL_LINE: DefensiveCoding */
}
len = ares_strlen(src);
@ -116,7 +116,7 @@ void ares__str_rtrim(char *str)
size_t i;
if (str == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
len = ares_strlen(str);
@ -134,7 +134,7 @@ void ares__str_ltrim(char *str)
size_t len;
if (str == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
for (i = 0; str[i] != 0 && ares__isspace(str[i]); i++) {
@ -262,7 +262,7 @@ ares_bool_t ares__is_hostname(const char *str)
size_t i;
if (str == NULL) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
for (i = 0; str[i] != 0; i++) {

@ -52,19 +52,19 @@ char **ares__strsplit_duplicate(char **elms, size_t num_elm)
char **out;
if (elms == NULL || num_elm == 0) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
out = ares_malloc_zero(sizeof(*elms) * num_elm);
if (out == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (i = 0; i < num_elm; i++) {
out[i] = ares_strdup(elms[i]);
if (out[i] == NULL) {
ares__strsplit_free(out, num_elm);
return NULL;
ares__strsplit_free(out, num_elm); /* LCOV_EXCL_LINE: OutOfMemory */
return NULL; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -82,7 +82,7 @@ char **ares__strsplit(const char *in, const char *delms, size_t *num_elm)
size_t idx = 0;
if (in == NULL || delms == NULL || num_elm == NULL) {
return NULL;
return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */
}
*num_elm = 0;
@ -108,8 +108,8 @@ char **ares__strsplit(const char *in, const char *delms, size_t *num_elm)
out = ares_malloc_zero(cnt * sizeof(*out));
if (out == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (node = ares__llist_node_first(llist); node != NULL;

@ -1007,7 +1007,7 @@ static ares_status_t ares_sysconfig_apply(ares_channel_t *channel,
char **temp =
ares__strsplit_duplicate(sysconfig->domains, sysconfig->ndomains);
if (temp == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
ares__strsplit_free(channel->domains, channel->ndomains);
@ -1018,7 +1018,7 @@ static ares_status_t ares_sysconfig_apply(ares_channel_t *channel,
if (sysconfig->lookups && !(channel->optmask & ARES_OPT_LOOKUPS)) {
char *temp = ares_strdup(sysconfig->lookups);
if (temp == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
ares_free(channel->lookups);
@ -1029,7 +1029,7 @@ static ares_status_t ares_sysconfig_apply(ares_channel_t *channel,
struct apattern *temp =
ares_malloc(sizeof(*channel->sortlist) * sysconfig->nsortlist);
if (temp == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
memcpy(temp, sysconfig->sortlist,
sizeof(*channel->sortlist) * sysconfig->nsortlist);

@ -103,7 +103,7 @@ static ares_bool_t sortlist_append(struct apattern **sortlist, size_t *nsort,
newsort = ares_realloc(*sortlist, (*nsort + 1) * sizeof(*newsort));
if (newsort == NULL) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: OutOfMemory */
}
*sortlist = newsort;
@ -223,7 +223,7 @@ ares_status_t ares__parse_sortlist(struct apattern **sortlist, size_t *nsort,
ares__llist_node_t *node = NULL;
if (sortlist == NULL || nsort == NULL || str == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (*sortlist != NULL) {
@ -262,8 +262,8 @@ ares_status_t ares__parse_sortlist(struct apattern **sortlist, size_t *nsort,
}
if (!sortlist_append(sortlist, nsort, &pat)) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -371,7 +371,7 @@ static ares_status_t config_lookup(ares_sysconfig_t *sysconfig,
ares_free(sysconfig->lookups);
sysconfig->lookups = ares_strdup(lookupstr);
if (sysconfig->lookups == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -462,7 +462,7 @@ ares_status_t ares__sysconfig_set_options(ares_sysconfig_t *sysconfig,
status = process_option(sysconfig, valbuf);
/* Out of memory is the only fatal condition */
if (status == ARES_ENOMEM) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -484,7 +484,7 @@ ares_status_t ares__init_by_environment(ares_sysconfig_t *sysconfig)
if (localdomain) {
char *temp = ares_strdup(localdomain);
if (temp == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = config_search(sysconfig, temp, 1);
ares_free(temp);

@ -67,11 +67,11 @@ static ares_bool_t ares__addr_match(const struct ares_addr *addr1,
const struct ares_addr *addr2)
{
if (addr1 == NULL && addr2 == NULL) {
return ARES_TRUE;
return ARES_TRUE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (addr1 == NULL || addr2 == NULL) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (addr1->family != addr2->family) {
@ -102,7 +102,7 @@ ares_bool_t ares__subnet_match(const struct ares_addr *addr,
size_t i;
if (addr == NULL || subnet == NULL) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
if (addr->family != subnet->family) {
@ -115,7 +115,7 @@ ares_bool_t ares__subnet_match(const struct ares_addr *addr,
len = 4;
if (netmask > 32) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
} else if (addr->family == AF_INET6) {
addr_ptr = (const unsigned char *)&addr->addr.addr6;
@ -123,10 +123,10 @@ ares_bool_t ares__subnet_match(const struct ares_addr *addr,
len = 16;
if (netmask > 128) {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
} else {
return ARES_FALSE;
return ARES_FALSE; /* LCOV_EXCL_LINE: DefensiveCoding */
}
for (i = 0; i < len && netmask > 0; i++) {
@ -380,7 +380,7 @@ ares_status_t ares__sconfig_append(ares__llist_t **sconfig,
ares_status_t status;
if (sconfig == NULL || addr == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
/* Silently skip blacklisted IPv6 servers. */
@ -390,14 +390,14 @@ ares_status_t ares__sconfig_append(ares__llist_t **sconfig,
s = ares_malloc_zero(sizeof(*s));
if (s == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (*sconfig == NULL) {
*sconfig = ares__llist_create(ares_free);
if (*sconfig == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -422,8 +422,8 @@ ares_status_t ares__sconfig_append(ares__llist_t **sconfig,
}
if (ares__llist_insert_last(*sconfig, s) == NULL) {
status = ARES_ENOMEM;
goto fail;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
return ARES_SUCCESS;
@ -491,7 +491,7 @@ ares_status_t ares__sconfig_append_fromstr(ares__llist_t **sconfig,
status = ares__sconfig_append(sconfig, &s.addr, s.udp_port, s.tcp_port,
s.ll_iface);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -585,7 +585,7 @@ static ares_status_t ares__server_create(ares_channel_t *channel,
struct server_state *server = ares_malloc_zero(sizeof(*server));
if (server == NULL) {
return ARES_ENOMEM;
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
}
server->idx = idx;
@ -612,32 +612,32 @@ static ares_status_t ares__server_create(ares_channel_t *channel,
server->tcp_parser = ares__buf_create();
if (server->tcp_parser == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
server->tcp_send = ares__buf_create();
if (server->tcp_send == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
server->connections = ares__llist_create(NULL);
if (server->connections == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (ares__slist_insert(channel->servers, server) == NULL) {
status = ARES_ENOMEM;
goto done;
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ARES_SUCCESS;
done:
if (status != ARES_SUCCESS) {
ares__destroy_server(server);
ares__destroy_server(server); /* LCOV_EXCL_LINE: OutOfMemory */
}
return status;
@ -708,7 +708,7 @@ ares_status_t ares__servers_update(ares_channel_t *channel,
ares_bool_t list_changed = ARES_FALSE;
if (channel == NULL) {
return ARES_EFORMERR;
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
}
ares__channel_lock(channel);
@ -796,7 +796,7 @@ static ares_status_t
s = ares__llist_create(ares_free);
if (s == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (node = servers; node != NULL; node = node->next) {
@ -809,7 +809,7 @@ static ares_status_t
sconfig = ares_malloc_zero(sizeof(*sconfig));
if (sconfig == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
sconfig->addr.family = node->family;
@ -822,17 +822,19 @@ static ares_status_t
}
if (ares__llist_insert_last(s, sconfig) == NULL) {
ares_free(sconfig);
goto fail;
ares_free(sconfig); /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
*llist = s;
return ARES_SUCCESS;
/* LCOV_EXCL_START: OutOfMemory */
fail:
ares__llist_destroy(s);
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
static ares_status_t ares_addr_port_node_to_server_config_llist(
@ -845,7 +847,7 @@ static ares_status_t ares_addr_port_node_to_server_config_llist(
s = ares__llist_create(ares_free);
if (s == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (node = servers; node != NULL; node = node->next) {
@ -858,7 +860,7 @@ static ares_status_t ares_addr_port_node_to_server_config_llist(
sconfig = ares_malloc_zero(sizeof(*sconfig));
if (sconfig == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
sconfig->addr.family = node->family;
@ -874,17 +876,19 @@ static ares_status_t ares_addr_port_node_to_server_config_llist(
sconfig->udp_port = (unsigned short)node->udp_port;
if (ares__llist_insert_last(s, sconfig) == NULL) {
ares_free(sconfig);
goto fail;
ares_free(sconfig); /* LCOV_EXCL_LINE: OutOfMemory */
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
*llist = s;
return ARES_SUCCESS;
/* LCOV_EXCL_START: OutOfMemory */
fail:
ares__llist_destroy(s);
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
ares_status_t ares_in_addr_to_server_config_llist(const struct in_addr *servers,
@ -898,7 +902,7 @@ ares_status_t ares_in_addr_to_server_config_llist(const struct in_addr *servers,
s = ares__llist_create(ares_free);
if (s == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (i = 0; servers != NULL && i < nservers; i++) {
@ -906,7 +910,7 @@ ares_status_t ares_in_addr_to_server_config_llist(const struct in_addr *servers,
sconfig = ares_malloc_zero(sizeof(*sconfig));
if (sconfig == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
sconfig->addr.family = AF_INET;
@ -914,16 +918,18 @@ ares_status_t ares_in_addr_to_server_config_llist(const struct in_addr *servers,
sizeof(sconfig->addr.addr.addr4));
if (ares__llist_insert_last(s, sconfig) == NULL) {
goto fail;
goto fail; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
*llist = s;
return ARES_SUCCESS;
/* LCOV_EXCL_START: OutOfMemory */
fail:
ares__llist_destroy(s);
return ARES_ENOMEM;
/* LCOV_EXCL_STOP */
}
/* Write out the details of a server to a buffer */
@ -937,7 +943,7 @@ ares_status_t ares_get_server_addr(const struct server_state *server,
if (server->addr.family == AF_INET6) {
status = ares__buf_append_byte(buf, '[');
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -945,37 +951,37 @@ ares_status_t ares_get_server_addr(const struct server_state *server,
status = ares__buf_append_str(buf, addr);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
if (server->addr.family == AF_INET6) {
status = ares__buf_append_byte(buf, ']');
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
/* :port */
status = ares__buf_append_byte(buf, ':');
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_num_dec(buf, server->udp_port, 0);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
/* %iface */
if (ares_strlen(server->ll_iface)) {
status = ares__buf_append_byte(buf, '%');
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
status = ares__buf_append_str(buf, server->ll_iface);
if (status != ARES_SUCCESS) {
return status;
return status; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -1195,7 +1201,7 @@ char *ares_get_servers_csv(const ares_channel_t *channel)
buf = ares__buf_create();
if (buf == NULL) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
for (node = ares__slist_node_first(channel->servers); node != NULL;
@ -1206,13 +1212,13 @@ char *ares_get_servers_csv(const ares_channel_t *channel)
if (ares__buf_len(buf)) {
status = ares__buf_append_byte(buf, ',');
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
status = ares_get_server_addr(server, buf);
if (status != ARES_SUCCESS) {
goto done;
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
}
}
@ -1229,7 +1235,7 @@ void ares_set_server_state_callback(ares_channel_t *channel,
ares_server_state_callback cb, void *data)
{
if (channel == NULL) {
return;
return; /* LCOV_EXCL_LINE: DefensiveCoding */
}
channel->server_state_cb = cb;
channel->server_state_cb_data = data;

@ -805,6 +805,50 @@ TEST_F(LibraryTest, DNSRecord) {
ares_dns_record_destroy(dnsrec);
ares_free_string(msg);
// Invalid
EXPECT_NE(ARES_SUCCESS, ares_dns_parse(NULL, 0, 0, NULL));
EXPECT_NE(ARES_SUCCESS, ares_dns_record_create(NULL, 0, 0, ARES_OPCODE_QUERY, ARES_RCODE_NOERROR));
EXPECT_EQ(0, ares_dns_record_get_id(NULL));
EXPECT_EQ(0, ares_dns_record_get_flags(NULL));
EXPECT_EQ(0, (int)ares_dns_record_get_opcode(NULL));
EXPECT_EQ(0, (int)ares_dns_record_get_rcode(NULL));
EXPECT_EQ(0, (int)ares_dns_record_query_cnt(NULL));
EXPECT_NE(ARES_SUCCESS, ares_dns_record_query_set_name(NULL, 0, NULL));
EXPECT_NE(ARES_SUCCESS, ares_dns_record_query_set_type(NULL, 0, ARES_REC_TYPE_A));
EXPECT_NE(ARES_SUCCESS, ares_dns_record_query_get(NULL, 0, NULL, NULL, NULL));
EXPECT_EQ(0, ares_dns_record_rr_cnt(NULL, ARES_SECTION_ANSWER));
EXPECT_NE(ARES_SUCCESS, ares_dns_record_rr_add(NULL, NULL, ARES_SECTION_ANSWER, NULL, ARES_REC_TYPE_A, ARES_CLASS_IN, 0));
EXPECT_NE(ARES_SUCCESS, ares_dns_record_rr_del(NULL, ARES_SECTION_ANSWER, 0));
EXPECT_EQ(nullptr, ares_dns_record_rr_get(NULL, ARES_SECTION_ANSWER, 0));
EXPECT_EQ(nullptr, ares_dns_rr_get_name(NULL));
EXPECT_EQ(0, (int)ares_dns_rr_get_type(NULL));
EXPECT_EQ(0, (int)ares_dns_rr_get_class(NULL));
EXPECT_EQ(0, ares_dns_rr_get_ttl(NULL));
EXPECT_NE(ARES_SUCCESS, ares_dns_write(NULL, NULL, NULL));
#ifndef CARES_SYMBOL_HIDING
ares_dns_record_write_ttl_decrement(NULL, 0);
#endif
EXPECT_EQ(nullptr, ares_dns_rr_get_addr(NULL, ARES_RR_A_ADDR));
EXPECT_EQ(nullptr, ares_dns_rr_get_addr(NULL, ARES_RR_NS_NSDNAME));
EXPECT_EQ(nullptr, ares_dns_rr_get_addr6(NULL, ARES_RR_AAAA_ADDR));
EXPECT_EQ(nullptr, ares_dns_rr_get_addr6(NULL, ARES_RR_NS_NSDNAME));
EXPECT_EQ(0, ares_dns_rr_get_u8(NULL, ARES_RR_SIG_ALGORITHM));
EXPECT_EQ(0, ares_dns_rr_get_u8(NULL, ARES_RR_NS_NSDNAME));
EXPECT_EQ(0, ares_dns_rr_get_u16(NULL, ARES_RR_MX_PREFERENCE));
EXPECT_EQ(0, ares_dns_rr_get_u16(NULL, ARES_RR_NS_NSDNAME));
EXPECT_EQ(0, ares_dns_rr_get_u32(NULL, ARES_RR_SOA_SERIAL));
EXPECT_EQ(0, ares_dns_rr_get_u32(NULL, ARES_RR_NS_NSDNAME));
EXPECT_EQ(nullptr, ares_dns_rr_get_bin(NULL, ARES_RR_TXT_DATA, NULL));
EXPECT_EQ(nullptr, ares_dns_rr_get_bin(NULL, ARES_RR_NS_NSDNAME, NULL));
EXPECT_EQ(nullptr, ares_dns_rr_get_str(NULL, ARES_RR_NS_NSDNAME));
EXPECT_EQ(nullptr, ares_dns_rr_get_str(NULL, ARES_RR_MX_PREFERENCE));
EXPECT_EQ(0, ares_dns_rr_get_opt_cnt(NULL, ARES_RR_OPT_OPTIONS));
EXPECT_EQ(0, ares_dns_rr_get_opt_cnt(NULL, ARES_RR_A_ADDR));
EXPECT_EQ(65535, ares_dns_rr_get_opt(NULL, ARES_RR_OPT_OPTIONS, 0, NULL, NULL));
EXPECT_EQ(65535, ares_dns_rr_get_opt(NULL, ARES_RR_A_ADDR, 0, NULL, NULL));
EXPECT_EQ(ARES_FALSE, ares_dns_rr_get_opt_byid(NULL, ARES_RR_OPT_OPTIONS, 1, NULL, NULL));
EXPECT_EQ(ARES_FALSE, ares_dns_rr_get_opt_byid(NULL, ARES_RR_A_ADDR, 1, NULL, NULL));
}
TEST_F(LibraryTest, DNSParseFlags) {
@ -1229,6 +1273,63 @@ TEST_F(LibraryTest, HtableStrvp) {
ares__htable_strvp_destroy(h);
}
TEST_F(LibraryTest, IfaceIPs) {
ares_status_t status;
ares__iface_ips_t *ips = NULL;
size_t i;
status = ares__iface_ips(&ips, ARES_IFACE_IP_DEFAULT, NULL);
EXPECT_TRUE(status == ARES_SUCCESS || status == ARES_ENOTIMP);
/* Not implemented, can't run tests */
if (status == ARES_ENOTIMP)
return;
EXPECT_NE(nullptr, ips);
for (i=0; i<ares__iface_ips_cnt(ips); i++) {
const char *name = ares__iface_ips_get_name(ips, i);
EXPECT_NE(nullptr, name);
int flags = (int)ares__iface_ips_get_flags(ips, i);
EXPECT_NE(0, (int)flags);
EXPECT_NE(nullptr, ares__iface_ips_get_addr(ips, i));
EXPECT_NE(0, ares__iface_ips_get_netmask(ips, i));
if (flags & ARES_IFACE_IP_LINKLOCAL && flags & ARES_IFACE_IP_V6) {
/* Hmm, seems not to work at least on MacOS
* EXPECT_NE(0, ares__iface_ips_get_ll_scope(ips, i));
*/
} else {
EXPECT_EQ(0, ares__iface_ips_get_ll_scope(ips, i));
}
unsigned int idx = ares__if_nametoindex(name);
EXPECT_NE(0, idx);
char namebuf[256];
EXPECT_EQ(std::string(ares__if_indextoname(idx, namebuf, sizeof(namebuf))), std::string(name));
}
/* Negative checking */
ares__iface_ips_get_name(ips, ares__iface_ips_cnt(ips));
ares__iface_ips_get_flags(ips, ares__iface_ips_cnt(ips));
ares__iface_ips_get_addr(ips, ares__iface_ips_cnt(ips));
ares__iface_ips_get_netmask(ips, ares__iface_ips_cnt(ips));
ares__iface_ips_get_ll_scope(ips, ares__iface_ips_cnt(ips));
ares__iface_ips(NULL, ARES_IFACE_IP_DEFAULT, NULL);
ares__iface_ips_cnt(NULL);
ares__iface_ips_get_name(NULL, 0);
ares__iface_ips_get_flags(NULL, 0);
ares__iface_ips_get_addr(NULL, 0);
ares__iface_ips_get_netmask(NULL, 0);
ares__iface_ips_get_ll_scope(NULL, 0);
ares__iface_ips_destroy(NULL);
ares__if_nametoindex(NULL);
ares__if_indextoname(0, NULL, 0);
ares__iface_ips_destroy(ips);
}
#endif
TEST_F(DefaultChannelTest, SaveInvalidChannel) {

@ -308,6 +308,9 @@ TEST_F(LibraryTest, CreateQueryFailures) {
ares_create_query("example..com", C_IN, T_A, 0x1234, 0,
&p, &len, 0));
if (p) ares_free_string(p);
EXPECT_EQ(ARES_EFORMERR,
ares_create_query(NULL, C_IN, T_A, 0x1234, 0, NULL, NULL, 0));
}
TEST_F(LibraryTest, CreateQueryOnionDomain) {
@ -544,15 +547,6 @@ TEST_F(LibraryTest, Version) {
EXPECT_EQ(ARES_VERSION, version);
}
TEST_F(LibraryTest, Strerror) {
EXPECT_EQ("Successful completion",
std::string(ares_strerror(ARES_SUCCESS)));
EXPECT_EQ("DNS query cancelled",
std::string(ares_strerror(ARES_ECANCELLED)));
EXPECT_EQ("unknown",
std::string(ares_strerror(99)));
}
TEST_F(LibraryTest, ExpandString) {
std::vector<byte> s1 = { 3, 'a', 'b', 'c'};
char* result = nullptr;
@ -576,5 +570,90 @@ TEST_F(LibraryTest, ExpandString) {
(unsigned char**)&result, &len));
}
TEST_F(LibraryTest, DNSMapping) {
ares_dns_rec_type_t types[] = {
ARES_REC_TYPE_A,
ARES_REC_TYPE_NS,
ARES_REC_TYPE_CNAME,
ARES_REC_TYPE_SOA,
ARES_REC_TYPE_PTR,
ARES_REC_TYPE_HINFO,
ARES_REC_TYPE_MX,
ARES_REC_TYPE_TXT,
ARES_REC_TYPE_SIG,
ARES_REC_TYPE_AAAA,
ARES_REC_TYPE_SRV,
ARES_REC_TYPE_NAPTR,
ARES_REC_TYPE_OPT,
ARES_REC_TYPE_TLSA,
ARES_REC_TYPE_SVCB,
ARES_REC_TYPE_HTTPS,
ARES_REC_TYPE_ANY,
ARES_REC_TYPE_URI,
ARES_REC_TYPE_CAA
};
for (size_t i=0; i<sizeof(types) / sizeof(*types); i++) {
ares_dns_rec_type_t type;
EXPECT_TRUE(ares_dns_rec_type_fromstr(&type, ares_dns_rec_type_tostr(types[i])));
EXPECT_EQ(types[i], type);
size_t cnt;
const ares_dns_rr_key_t *keys = ares_dns_rr_get_keys(type, &cnt);
for (size_t j=0; j<cnt; j++) {
const char *name = ares_dns_rr_key_tostr(keys[j]);
EXPECT_NE(nullptr, name);
EXPECT_NE("UNKNOWN", std::string(name));
EXPECT_EQ(type, ares_dns_rr_key_to_rec_type(keys[j]));
EXPECT_NE(0, (int)ares_dns_rr_key_datatype(keys[j]));
}
}
}
TEST_F(LibraryTest, StrError) {
ares_status_t status[] = {
ARES_SUCCESS, ARES_ENODATA, ARES_EFORMERR, ARES_ESERVFAIL, ARES_ENOTFOUND,
ARES_ENOTIMP, ARES_EREFUSED, ARES_EBADQUERY, ARES_EBADNAME, ARES_EBADFAMILY,
ARES_EBADRESP, ARES_ECONNREFUSED, ARES_ETIMEOUT, ARES_EOF, ARES_EFILE,
ARES_ENOMEM, ARES_EDESTRUCTION, ARES_EBADSTR, ARES_EBADFLAGS, ARES_ENONAME,
ARES_EBADHINTS, ARES_ENOTINITIALIZED, ARES_ELOADIPHLPAPI,
ARES_EADDRGETNETWORKPARAMS, ARES_ECANCELLED, ARES_ESERVICE, ARES_ENOSERVER
};
size_t i;
const char *str = nullptr;
for (i=0; i < sizeof(status) / sizeof(*status); i++) {
str = ares_strerror((int)status[i]);
EXPECT_NE(nullptr, str);
EXPECT_NE("unknown", std::string(str));
}
/* unknown value */
str = ares_strerror(0x12345678);
EXPECT_NE(nullptr, str);
EXPECT_EQ("unknown", std::string(str));
}
TEST_F(LibraryTest, UsageErrors) {
ares_cancel(NULL);
ares_set_socket_callback(NULL, NULL, NULL);
ares_set_socket_configure_callback(NULL, NULL, NULL);
ares_set_socket_functions(NULL, NULL, NULL);
ares_destroy(NULL);
ares_expand_name(NULL, NULL, 0, NULL, NULL);
ares_expand_string(NULL, NULL, 0, NULL, NULL);
ares_fds(NULL, NULL, NULL);
ares_getaddrinfo(NULL, NULL, NULL, NULL, NULL, NULL);
ares_gethostbyaddr(NULL, NULL, 0, 0, NULL, NULL);
ares_getnameinfo(NULL, NULL, 0, 0, NULL, NULL);
ares_reinit(NULL);
ares_dup(NULL, NULL);
ares_set_local_ip4(NULL, 0);
ares_set_local_ip6(NULL, NULL);
ares_set_local_dev(NULL, NULL);
ares_query_dnsrec(NULL, NULL, ARES_CLASS_IN, ARES_REC_TYPE_A, NULL, NULL, NULL);
ares_query(NULL, NULL, ARES_CLASS_IN, ARES_REC_TYPE_A, NULL, NULL);
}
} // namespace test
} // namespace ares

@ -139,6 +139,10 @@ TEST_F(LibraryTest, ParseMalformedAReply) {
// Truncate mid-answer.
EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), 42,
&host, info, &count));
// Negative length
EXPECT_EQ(ARES_EBADRESP, ares_parse_a_reply(data.data(), -1,
&host, info, &count));
}
TEST_F(LibraryTest, ParseAReplyNoData) {

@ -195,6 +195,10 @@ TEST_F(LibraryTest, ParseAaaaReplyErrors) {
EXPECT_EQ(ARES_EBADRESP, ares_parse_aaaa_reply(data.data(), (int)len,
nullptr, info, &count));
}
// Negative length
EXPECT_EQ(ARES_EBADRESP, ares_parse_aaaa_reply(data.data(), -1,
&host, info, &count));
}
TEST_F(LibraryTest, ParseAaaaReplyAllocFail) {

@ -134,5 +134,20 @@ TEST_F(LibraryTest, ParseCaaEmptyReply) {
ASSERT_EQ(nullptr, caa);
}
TEST_F(LibraryTest, ParseNegativeReply) {
std::vector<byte> data = {
0x27, 0x86, 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x09, 0x77, 0x69, 0x6B, // '............wik
0x69, 0x70, 0x65, 0x64, 0x69, 0x61, 0x02, 0x64, 0x65, 0x00, 0x01, 0x01, 0x00, 0x01, 0xC0, 0x0C, // ipedia.de.......
0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x02, 0x58, 0x00, 0x3B, 0x04, 0x6E, 0x73, 0x38, 0x31, 0x0D, // .......X.;.ns81.
0x64, 0x6F, 0x6D, 0x61, 0x69, 0x6E, 0x63, 0x6F, 0x6E, 0x74, 0x72, 0x6F, 0x6C, 0x03, 0x63, 0x6F, // domaincontrol.co
0x6D, 0x00, 0x03, 0x64, 0x6E, 0x73, 0x05, 0x6A, 0x6F, 0x6D, 0x61, 0x78, 0x03, 0x6E, 0x65, 0x74, // m..dns.jomax.net
0x00, 0x78, 0x67, 0xFE, 0x34, 0x00, 0x00, 0x70, 0x80, 0x00, 0x00, 0x1C, 0x20, 0x00, 0x09, 0x3A, // .xg.4..p.... ..:
0x80, 0x00, 0x00, 0x02, 0x58 // ....X
};
struct ares_caa_reply* caa = nullptr;
EXPECT_EQ(ARES_EBADRESP, ares_parse_caa_reply(data.data(), -1, &caa));
}
} // namespace test
} // namespace ares

@ -144,6 +144,9 @@ TEST_F(LibraryTest, ParseMxReplyErrors) {
EXPECT_EQ(nullptr, mx);
EXPECT_TRUE(rc == ARES_EBADRESP || rc == ARES_EBADNAME);
}
// Negative Length
EXPECT_EQ(ARES_EBADRESP, ares_parse_mx_reply(data.data(), -1, &mx));
}
TEST_F(LibraryTest, ParseMxReplyAllocFail) {

@ -120,6 +120,9 @@ TEST_F(LibraryTest, ParseNaptrReplyErrors) {
int rc = ares_parse_naptr_reply(data.data(), (int)len, &naptr);
EXPECT_TRUE(rc == ARES_EBADRESP || rc == ARES_EBADNAME);
}
// Negative Length
EXPECT_EQ(ARES_EBADRESP, ares_parse_naptr_reply(data.data(), -1, &naptr));
}
TEST_F(LibraryTest, ParseNaptrReplyTooShort) {

@ -121,6 +121,9 @@ TEST_F(LibraryTest, ParseNsReplyErrors) {
for (size_t len = 1; len < data.size(); len++) {
EXPECT_EQ(ARES_EBADRESP, ares_parse_ns_reply(data.data(), (int)len, &host));
}
// Negative Length
EXPECT_EQ(ARES_EBADRESP, ares_parse_ns_reply(data.data(), -1, &host));
}
TEST_F(LibraryTest, ParseNsReplyAllocFail) {

@ -223,6 +223,10 @@ TEST_F(LibraryTest, ParsePtrReplyErrors) {
addrv4, sizeof(addrv4), AF_INET, &host));
EXPECT_EQ(nullptr, host);
}
// Negative Length
EXPECT_EQ(ARES_EBADRESP, ares_parse_ptr_reply(data.data(), -1,
addrv4, sizeof(addrv4), AF_INET, &host));
}
TEST_F(LibraryTest, ParsePtrReplyAllocFailSome) {

@ -113,6 +113,9 @@ TEST_F(LibraryTest, ParseSoaAnyReplyErrors) {
for (size_t len = 1; len < data.size(); len++) {
EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), (int)len, &soa));
}
// Negative Length
EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), -1, &soa));
}
TEST_F(LibraryTest, ParseSoaAnyReplyAllocFail) {

@ -110,6 +110,9 @@ TEST_F(LibraryTest, ParseSoaReplyErrors) {
for (size_t len = 1; len < data.size(); len++) {
EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), (int)len, &soa));
}
// Negative Length
EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), -1, &soa));
}
TEST_F(LibraryTest, ParseSoaReplyAllocFail) {

@ -291,6 +291,9 @@ TEST_F(LibraryTest, ParseSrvReplyErrors) {
int rc = ares_parse_srv_reply(data.data(), (int)len, &srv);
EXPECT_TRUE(rc == ARES_EBADRESP || rc == ARES_EBADNAME);
}
// Negative Length
EXPECT_EQ(ARES_EBADRESP, ares_parse_srv_reply(data.data(), -1, &srv));
}
TEST_F(LibraryTest, ParseSrvReplyAllocFail) {

@ -212,6 +212,7 @@ TEST_F(LibraryTest, ParseTxtReplyErrors) {
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b}));
std::vector<byte> data = pkt.data();
struct ares_txt_reply* txt = nullptr;
struct ares_txt_ext* txt_ext = nullptr;
// No question.
pkt.questions_.clear();
@ -254,6 +255,10 @@ TEST_F(LibraryTest, ParseTxtReplyErrors) {
EXPECT_NE(ARES_SUCCESS, ares_parse_txt_reply(data.data(), (int)len, &txt));
EXPECT_EQ(nullptr, txt);
}
// Negative Length
EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), -1, &txt));
EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply_ext(data.data(), -1, &txt_ext));
}
TEST_F(LibraryTest, ParseTxtReplyAllocFail) {

@ -291,6 +291,9 @@ TEST_F(LibraryTest, ParseUriReplyErrors) {
int rc = ares_parse_uri_reply(data.data(), (int)len, &uri);
EXPECT_TRUE(rc == ARES_EBADRESP || rc == ARES_EBADNAME);
}
// Negative Length
EXPECT_EQ(ARES_EBADRESP, ares_parse_uri_reply(data.data(), -1, &uri));
}
TEST_F(LibraryTest, ParseUriReplyAllocFail) {

Loading…
Cancel
Save