Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--dns-servers flag and CURLOPT_DNS_SERVERS ignores port number #4066

Closed
Roguelazer opened this issue Jun 24, 2019 · 1 comment
Closed

--dns-servers flag and CURLOPT_DNS_SERVERS ignores port number #4066

Roguelazer opened this issue Jun 24, 2019 · 1 comment
Labels
name lookup DNS and related tech

Comments

@Roguelazer
Copy link
Contributor

Roguelazer commented Jun 24, 2019

I did this

Started a DNS server on localhost:5353 and ran curl --dns-servers 127.0.0.1:5353 www.example.com

The documentation indicated that port numbers are passed through to c-ares; however, I believe that this is not the case.

I expected the following

curl to make a DNS request to 127.0.0.1:5353

What happened instead?

curl made a DNS request to 127.0.0.1:53. I confirmed with strace that nothing ever tried to talk to :5353 and that starting my custom server as root on port 53 instead worked.

curl/libcurl version

curl 7.65.1 (x86_64-redhat-linux-gnu) libcurl/7.65.1 OpenSSL/1.0.2s zlib/1.2.3 c-ares/1.15.0 libidn2/2.0.5 libssh2/1.8.2 nghttp2/1.39.1
Release-Date: 2019-06-05
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB SPNEGO SSL UnixSockets

operating system

CentOS 6

I believe the following patch will fix this issue

diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c
index 8561a4724..198d3d6e6 100644
--- a/lib/asyn-ares.c
+++ b/lib/asyn-ares.c
@@ -734,7 +734,11 @@ CURLcode Curl_set_dns_servers(struct Curl_easy *data,
     return CURLE_OK;
 
 #if (ARES_VERSION >= 0x010704)
+#if (ARES_VERSION >= 0x011100)
+  ares_result = ares_set_servers_ports_csv(data->state.resolver, servers);
+#else
   ares_result = ares_set_servers_csv(data->state.resolver, servers);
+#endif
   switch(ares_result) {
   case ARES_SUCCESS:
     result = CURLE_OK;

I have not tested this patch and there do not appear to be any unit tests of this functionality.

@bagder bagder added the name lookup DNS and related tech label Jun 24, 2019
@bagder
Copy link
Member

bagder commented Jun 24, 2019

Thanks! The report and fix seem correct.

Can you turn the fix into a PR or would you like me to do it for you?

@Roguelazer Roguelazer changed the title --dns-resolvers flag and CURLOPT_DNS_SERVERS ignores port number --dns-servers flag and CURLOPT_DNS_SERVERS ignores port number Jun 24, 2019
@bagder bagder closed this as completed in d331227 Jun 24, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
name lookup DNS and related tech
2 participants