From de9ada46a368f11d0ddeff26dd5f4189f9cbe3e8 Mon Sep 17 00:00:00 2001 From: Kamary <6436370+kamarya@users.noreply.github.com> Date: Tue, 1 Sep 2020 23:14:19 -0400 Subject: [PATCH] bug fix: when there is no Answer send SERVFAIL --- dnsd.conf | 2 +- inc/dnssec.h | 2 +- src/dnssec.c | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dnsd.conf b/dnsd.conf index 59bef37..f16342d 100644 --- a/dnsd.conf +++ b/dnsd.conf @@ -6,7 +6,7 @@ # https_proxy=: # The default server URL is set below. -server_url = https://dns.google.com +server_url = https://8.8.8.8 # The local service ip and port service_port = 53 diff --git a/inc/dnssec.h b/inc/dnssec.h index df240f6..02eeae6 100644 --- a/inc/dnssec.h +++ b/inc/dnssec.h @@ -47,7 +47,7 @@ #define DNS_SOA_RECORD 0x0006 #define DNS_MX_RECORD 0x000F #define DNS_OPT_RECORD 0x0029 -#define DNS_AAA_RECORD 0x001C +#define DNS_AAAA_RECORD 0x001C #define MAX_DOMAIN_LENGTH 255 #define MAX_SUBDOMAIN_LENGTH 63 diff --git a/src/dnssec.c b/src/dnssec.c index 7544097..7744cab 100644 --- a/src/dnssec.c +++ b/src/dnssec.c @@ -200,7 +200,7 @@ int https_query (struct dns_query* query) // failed to work with libcurl/7.65.3 and HTTP/2.0 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); - + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_TIMEOUT, options.server_timeout); if (options.https_proxy[0]) @@ -378,7 +378,7 @@ int server() } } - if (!answer_length) + if (!answer_length || answer_length == JSON_NO_ANSWER) { header->rcode = DNS_SERVER_FAILURE; answer_length = 0; // the returned value may be less than zero to indicate the error code. @@ -512,7 +512,11 @@ size_t json_to_answer(char* answer, struct dns_header_detail* header, size_t max char* token = strstr(json, "Answer"); - if (token == NULL) return JSON_NO_ANSWER; + if (token == NULL) + { + LOG_DEBUG("no 'Answer' was found"); + return JSON_NO_ANSWER; + } uint16_t num_answers = 0; uint16_t num_additionals = 0; @@ -529,7 +533,7 @@ size_t json_to_answer(char* answer, struct dns_header_detail* header, size_t max type = atoi(ctype); if (type != DNS_A_RECORD && - type != DNS_AAA_RECORD && + type != DNS_AAAA_RECORD && type != DNS_CNAME_RECORD && type != DNS_NS_RECORD && type != DNS_MX_RECORD) @@ -584,7 +588,7 @@ size_t json_to_answer(char* answer, struct dns_header_detail* header, size_t max padd = 4 + DNS_ANSWER_LEN; } - else if (type == DNS_AAA_RECORD) + else if (type == DNS_AAAA_RECORD) { ans->rdlen = htons(INET_ADDRSTRLEN); rdata = (char *)(answer + DNS_ANSWER_LEN); @@ -679,7 +683,7 @@ char* getTypeString(uint16_t type, int unknown) { switch(type) { - case DNS_AAA_RECORD: + case DNS_AAAA_RECORD: return "AAAA"; break; case DNS_A_RECORD: