Skip to content

Commit

Permalink
bug fix: when there is no Answer send SERVFAIL
Browse files Browse the repository at this point in the history
  • Loading branch information
kamarya committed Sep 2, 2020
1 parent 99bd533 commit de9ada4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dnsd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# https_proxy=<IP>:<PORT>

# 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
Expand Down
2 changes: 1 addition & 1 deletion inc/dnssec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/dnssec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit de9ada4

Please sign in to comment.