]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
netrc: deal with null token better
authorDaniel Stenberg <daniel@haxx.se>
Wed, 14 May 2025 22:05:11 +0000 (00:05 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 14 May 2025 22:48:10 +0000 (00:48 +0200)
If there is no length of the token, assign a blank string to avoid
risking it being NULL.

Pointed out by Coverity

Closes #17351

lib/netrc.c

index 971e4b81de2236eeacae11bb0382c3af64a6587b..7df3f17fc3ae4dc15b153d655ffd369c6490856b 100644 (file)
@@ -220,7 +220,12 @@ static NETRCcode parsenetrc(struct store_netrc *store,
         }
       }
 
-      tok = curlx_dyn_ptr(&token);
+      if(curlx_dyn_len(&token))
+        tok = curlx_dyn_ptr(&token);
+      else
+        /* since tok might actually be NULL for no content, set it to blank
+           to avoid having to deal with it being NULL */
+        tok = "";
 
       switch(state) {
       case NOTHING:
@@ -247,7 +252,7 @@ static NETRCcode parsenetrc(struct store_netrc *store,
         }
         break;
       case MACDEF:
-        if(!tok || !*tok)
+        if(!*tok)
           state = NOTHING;
         break;
       case HOSTFOUND:
@@ -268,7 +273,7 @@ static NETRCcode parsenetrc(struct store_netrc *store,
           else {
             our_login = TRUE;
             free(login);
-            login = strdup(tok ? tok : "");
+            login = strdup(tok);
             if(!login) {
               retcode = NETRC_OUT_OF_MEMORY; /* allocation failed */
               goto out;