Skip to content

Commit

Permalink
asyn-ares: acknowledge CURLOPT_DNS_SERVERS set to NULL
Browse files Browse the repository at this point in the history
Since c-ares has no function to restore this value to default, it
instead closes and re-inits the c-ares channel.

Reported-by: Deniz Sökmen
Fixes curl#16015
Closes curl#16016
  • Loading branch information
bagder committed Jan 16, 2025
1 parent f241ccf commit 13afb11
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/asyn-ares.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,14 +838,26 @@ CURLcode Curl_set_dns_servers(struct Curl_easy *data,
CURLcode result = CURLE_NOT_BUILT_IN;
int ares_result;

/* If server is NULL or empty, this would purge all DNS servers
* from ares library, which will cause any and all queries to fail.
* So, just return OK if none are configured and do not actually make
* any changes to c-ares. This lets c-ares use its defaults, which
* it gets from the OS (for instance from /etc/resolv.conf on Linux).
/* If server is NULL, this purges all DNS servers from c-ares. Reset it to
* default.
*/
if(!(servers && servers[0]))
return CURLE_OK;
if(!servers) {
Curl_resolver_cleanup(data->state.async.resolver);
result = Curl_resolver_init(data, &data->state.async.resolver);
if(!result) {
/* this now needs to restore the other options set to c-ares */
if(data->set.str[STRING_DNS_INTERFACE])
(void)Curl_set_dns_interface(data,
data->set.str[STRING_DNS_INTERFACE]);
if(data->set.str[STRING_DNS_LOCAL_IP4])
(void)Curl_set_dns_local_ip4(data,
data->set.str[STRING_DNS_LOCAL_IP4]);
if(data->set.str[STRING_DNS_LOCAL_IP6])
(void)Curl_set_dns_local_ip6(data,
data->set.str[STRING_DNS_LOCAL_IP6]);
}
return result;
}

#ifdef HAVE_CARES_SERVERS_CSV
#ifdef HAVE_CARES_PORTS_CSV
Expand Down

0 comments on commit 13afb11

Please sign in to comment.