From: Orgad Shaneh Date: Wed, 3 Aug 2022 16:13:07 +0000 (+0300) Subject: url: really use the user provided in the url when netrc entry exists X-Git-Tag: curl-7_85_0~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c40ec3178f8ce10927c1c0dc566aada24a5ee76f;p=thirdparty%2Fcurl.git url: really use the user provided in the url when netrc entry exists If the user is specified as part of the URL, and the same user exists in .netrc, Authorization header was not sent at all. The user and password fields were assigned in conn->user and password but the user was not assigned to data->state.aptr, which is the field that is used in output_auth_headers and friends. Fix by assigning the user also to aptr. Amends commit d1237ac906ae7e3cd7a22c3a2d3a135a97edfbf5. Fixes #9243 --- diff --git a/lib/url.c b/lib/url.c index 33c6a2135a..bfc784ff39 100644 --- a/lib/url.c +++ b/lib/url.c @@ -3047,8 +3047,6 @@ static CURLcode override_login(struct Curl_easy *data, conn->user = strdup(*userp); if(!conn->user) return CURLE_OUT_OF_MEMORY; - /* don't update the user name below */ - userp = NULL; } /* no user was set but a password, set a blank user */ if(userp && !*userp && *passwdp) { @@ -3060,22 +3058,20 @@ static CURLcode override_login(struct Curl_easy *data, #endif /* for updated strings, we update them in the URL */ - if(userp) { - if(*userp) { - CURLcode result = Curl_setstropt(&data->state.aptr.user, *userp); - if(result) - return result; - } - if(data->state.aptr.user) { - uc = curl_url_set(data->state.uh, CURLUPART_USER, data->state.aptr.user, - CURLU_URLENCODE); - if(uc) - return Curl_uc_to_curlcode(uc); - if(!*userp) { - *userp = strdup(data->state.aptr.user); - if(!*userp) - return CURLE_OUT_OF_MEMORY; - } + if(*userp) { + CURLcode result = Curl_setstropt(&data->state.aptr.user, *userp); + if(result) + return result; + } + if(data->state.aptr.user) { + uc = curl_url_set(data->state.uh, CURLUPART_USER, data->state.aptr.user, + CURLU_URLENCODE); + if(uc) + return Curl_uc_to_curlcode(uc); + if(!*userp) { + *userp = strdup(data->state.aptr.user); + if(!*userp) + return CURLE_OUT_OF_MEMORY; } } if(*passwdp) {