-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
curl_easy_getinfo CURLINFO_EFFECTIVE_URL not retrieveing the last used url #15984
Comments
Yeah it shouldn't do that. The doc says "CURLOPT_CURLU explicitly overrides CURLOPT_URL" but internally data->state.url is not reset when a new CURLU is passed in as it is for URL. Here's the relevant code: Lines 2198 to 2203 in 75a2079
Lines 2109 to 2120 in 75a2079
Lines 556 to 565 in 75a2079
It can be solved in setopt or transfer, or maybe both? Here's what it would look like for setopt: diff --git a/lib/setopt.c b/lib/setopt.c
index 7366d4a..e9aed30 100644
--- a/lib/setopt.c
+++ b/lib/setopt.c
@@ -2191,6 +2191,13 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option,
/*
* pass CURLU to set URL
*/
+ if(data->state.url_alloc) {
+ /* the already set URL is allocated, free it first! */
+ Curl_safefree(data->state.url);
+ data->state.url_alloc = FALSE;
+ }
+ data->state.url = NULL;
+ data->set.str[STRING_SET_URL] = NULL;
data->set.uh = (CURLU *)ptr;
break;
case CURLOPT_SSLCERT: More change may be needed in transfer I'm not sure yet. |
@nsanmartin's recipe here is also a great foundation for creating a test case |
I agree. I started writing something similar in a new test but it's failing so far. There are other changes I made to transfer.c that may have something to do with it. Also, there is already test658 (lib658) that is supposed to test the CURLOPT_CURLU override of CURLOPT_URL, but does not test the multiple transfer principle. |
test 658 tests if |
- Change setopt and pretransfer to always reset URL related variables for a CURLU handle set CURLOPT_CURLU. This change is to ensure we are in compliance with the doc which says CURLU handles must be able to override a URL set via CURLOPT_URL and that if the contents of the CURLU handle changes between transfers then the updated contents must be used. Prior to this change, although subsequent transfers appear to be performed correctly in those cases, the work URL `data->state.url` was not updated. CURLINFO_EFFECTIVE_URL returns data->state.url to the user so it would return the URL from the initial transfer which was the wrong URL. It's likely there are other cases as well. Ref: https://curl.se/libcurl/c/CURLOPT_CURLU.html Reported-by: Nicolás San Martín Fixes curl#15984 Closes #xxxx
Yes. I made a separate test and didn't touch 658. It failed in address sanitizer because I forgot to free Proposed fix in #15985 |
Thanks |
I did this
I am using
curl_easy_getinfo
to getCURLINFO_EFFECTIVE_URL
but I am not getting the last url used. I pass the url usingCURLU*
and while the data downloaded is the expected one, the effective url is not. Instead I get the previous one used.Example:
I expected the following
I expected the last effective used to be printed, "https://libera.chat" in the example, but instead it was "https://curl.se".
curl/libcurl version
curl 8.9.1 (x86_64-pc-linux-gnu) libcurl/8.9.1 OpenSSL/3.3.1 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 libidn2/2.3.7 libpsl/0.21.2 libssh2/1.11.0 nghttp2/1.62.1 librtmp/2.3 OpenLDAP/2.6.8
Release-Date: 2024-07-31, security patched: 8.9.1-2ubuntu2.2
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd
operating system
Linux 6.11.0-13-generic #14-Ubuntu SMP PREEMPT_DYNAMIC Sat Nov 30 23:51:51 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: