]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
url: really use the user provided in the url when netrc entry exists
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>
Wed, 3 Aug 2022 16:13:07 +0000 (19:13 +0300)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 29 Aug 2022 15:25:29 +0000 (17:25 +0200)
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

lib/url.c

index 33c6a2135a12141f08cd114446c2fc7620113a55..bfc784ff39c7475d292640449088c482ff67f054 100644 (file)
--- 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) {