From 86034227ca47ea256186372f09f83a4e18fcdc01 Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Wed, 29 Jul 2015 12:58:23 -0500 Subject: dns_core: Allow zero-length DNS responses. A testsuite test recently failed due to a crash that occurred in the DNS core. The problem was that the test could not resolve an address, did not set a result on the DNS query, and then indicated the query was completed. The DNS core does not handle the case of a query with no result gracefully, and so there is a crash. This changeset makes the DNS system resolver set a result with a zero-length answer in the case that a DNS resolution failure occurs early. The DNS core now also will accept such a response without treating it as invalid input. A unit test was updated to no longer treat setting a zero-length response as off-nominal. Change-Id: Ie56641e22debdaa61459e1c9a042e23b78affbf6 --- main/dns.c | 1 + main/dns_core.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'main') diff --git a/main/dns.c b/main/dns.c index 409ed44ad..e1b7770bf 100644 --- a/main/dns.c +++ b/main/dns.c @@ -559,6 +559,7 @@ enum ast_dns_search_result ast_search_dns_ex(void *context, const char *dname, i if (dns_response_len < 0) { ast_log(LOG_ERROR, "DNS search failed for %s\n", dname); + response_handler(context, (unsigned char *)"", 0, ns_r_nxdomain); return AST_DNS_SEARCH_FAILURE; } diff --git a/main/dns_core.c b/main/dns_core.c index 0b471db91..cfce8efb0 100644 --- a/main/dns_core.c +++ b/main/dns_core.c @@ -399,10 +399,10 @@ int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int secure return -1; } - if (!answer || answer_size == 0) { - ast_debug(2, "Query '%p': Could not set result information since no DNS answer was provided\n", - query); - return -1; + if (!answer) { + answer = ""; + answer_size = 0; + ast_debug(2, "Query '%p': Assuming zero-sized answer on NULL input\n", query); } ast_dns_result_free(query->result); -- cgit v1.2.3