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

Using IPV6 host in CURLOPT_RESOLVE or --resolve results in a malformed/illegal address error #16357

Closed
rmg-x opened this issue Feb 16, 2025 · 6 comments · Fixed by #16358
Closed
Assignees
Labels
name lookup DNS and related tech

Comments

@rmg-x
Copy link

rmg-x commented Feb 16, 2025

I did this

On the command line:

curl -v --resolve "2606:4700:4700::1111:443:2606:4700:4700::1111" https://[2606:4700:4700::1111]
curl -v --resolve "2606:4700:4700::1111:443:[2606:4700:4700::1111]" https://[2606:4700:4700::1111]
curl -v --resolve "[2606:4700:4700::1111]:443:2606:4700:4700::1111" https://[2606:4700:4700::1111]
curl -v --resolve "[2606:4700:4700::1111]:443:[2606:4700:4700::1111]" https://[2606:4700:4700::1111]

which all resulted in the following error:

* Resolve address '4700::1111:443:[2606:4700:4700::1111]' found illegal!
* Couldn't parse CURLOPT_RESOLVE entry '2606:4700:4700::1111:443:[2606:4700:4700::1111]'!
curl: (49) Couldn't parse CURLOPT_RESOLVE entry '2606:4700:4700::1111:443:[2606:4700:4700::1111]'!

With libcurl (and the same combinations with square brackets above):

#include <curl/curl.h>
#include <stdio.h>

int main(void) {
  CURL *curl = curl_easy_init();
  struct curl_slist *host = curl_slist_append(NULL, "2606:4700:4700::1111:443:2606:4700:4700::1111");

  curl_version_info_data *version_data = curl_version_info(CURLVERSION_NOW);
  printf("libcurl version: %s\n", version_data->version);

  if (curl) {
    curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
    curl_easy_setopt(curl, CURLOPT_URL, "https://[2606:4700:4700::1111]");

    CURLcode res = curl_easy_perform(curl);
    if (res != CURLE_OK) {
      printf("error: %s", curl_easy_strerror(res));
    }

    curl_easy_cleanup(curl);
  }

  curl_slist_free_all(host);
}

results in:

libcurl version: 7.81.0
error: Malformed option provided in a setopt

I expected the following

The IPV6 host section to be parsed correctly since 1.1.1.1:443:1.1.1.1 works as expected.

curl/libcurl version

curl 7.81.0
libcurl 7.81.0

operating system

Linux desktop 5.15.0-131-generic #141-Ubuntu SMP Fri Jan 10 21:18:28 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

@bagder
Copy link
Member

bagder commented Feb 16, 2025

I suppose we never properly considered using this option to replace IP addresses.

@jay
Copy link
Member

jay commented Feb 16, 2025

I don't know why anyone would do that

@jay
Copy link
Member

jay commented Feb 16, 2025

@rmg-x maybe --connect-to can do what you want? it matches by string so the ip address would have to match exactly as in the url

curl -v --connect-to "[2606:4700:4700::1111]::[2607:f8b0:4006:816::200e]:" https://[2606:4700:4700::1111]

@rmg-x
Copy link
Author

rmg-x commented Feb 16, 2025

This was found while working on the Ladybird browser project which uses libcurl in the backend to handle requests. It has its own DNS resolver capability so that, in the future, users have full control over that process rather than delegating to an underlying/system resolver. It's slightly odd but on each request, CURLOPT_RESOLVE is specified so the resolution is guaranteed to be coming from the internal resolver. I'm not a maintainer of Ladybird so I'm not speaking on behalf of that project, but that is how I understand it to work currently.

Given the fact that IPV4 addresses work correctly in this case, I'd expect the IPV6 equivalent to as well.

@jay jay added the name lookup DNS and related tech label Feb 16, 2025
@bagder
Copy link
Member

bagder commented Feb 17, 2025

so the resolution is guaranteed to be coming from the internal resolver

Sure, for a name that gets resolved such reasoning makes sense but for a numerical IP address, it really does not.

Still, a bug.

bagder added a commit that referenced this issue Feb 17, 2025
This also applies to --resolve of course.

Fixes #16357
Reported-by: rmg-x on github
@rmg-x
Copy link
Author

rmg-x commented Feb 17, 2025

Sure, for a name that gets resolved such reasoning makes sense but for a numerical IP address, it really does not.

Sorry for being unclear, I was just explaining how it was found. I definitely don't think this is a normal or common use case 😅

I appreciate the quick responses and PR to address this!

bagder added a commit that referenced this issue Feb 17, 2025
This also applies to --resolve of course.

Fixes #16357
Reported-by: rmg-x on github
bagder added a commit that referenced this issue Feb 17, 2025
This also applies to --resolve of course.

Applied strparse functions on the function.

Fixes #16357
Reported-by: rmg-x on github
Closes #16358
@bagder bagder closed this as completed in 2f4dc65 Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
name lookup DNS and related tech
Development

Successfully merging a pull request may close this issue.

3 participants