]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_writeout: protect fputs() from NULL
authorDaniel Stenberg <daniel@haxx.se>
Tue, 15 Sep 2020 13:53:13 +0000 (15:53 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 15 Sep 2020 20:52:51 +0000 (22:52 +0200)
When the code was changed to do fputs() instead of fprintf() it got
sensitive for NULL pointers; add checks for that.

Follow-up from 0c1e767e83ec66

Closes #5963

src/tool_writeout.c

index 63d2cd003c035b164b374347c0a5603c945dd949..393e1686175b3b5ffdd2045de74dc61377a15fcb 100644 (file)
@@ -284,9 +284,8 @@ void ourWriteOut(CURL *curl, struct per_transfer *per, const char *writeinfo)
                   fputs(per->outs.filename, stream);
                 break;
               case VAR_PRIMARY_IP:
-                if(CURLE_OK ==
-                   curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP,
-                                     &stringp))
+                if((CURLE_OK == curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP,
+                                                  &stringp)) && stringp)
                   fputs(stringp, stream);
                 break;
               case VAR_PRIMARY_PORT:
@@ -296,9 +295,8 @@ void ourWriteOut(CURL *curl, struct per_transfer *per, const char *writeinfo)
                   fprintf(stream, "%ld", longinfo);
                 break;
               case VAR_LOCAL_IP:
-                if(CURLE_OK ==
-                   curl_easy_getinfo(curl, CURLINFO_LOCAL_IP,
-                                     &stringp))
+                if((CURLE_OK == curl_easy_getinfo(curl, CURLINFO_LOCAL_IP,
+                                                  &stringp)) && stringp)
                   fputs(stringp, stream);
                 break;
               case VAR_LOCAL_PORT:
@@ -331,9 +329,8 @@ void ourWriteOut(CURL *curl, struct per_transfer *per, const char *writeinfo)
                 }
                 break;
               case VAR_SCHEME:
-                if(CURLE_OK ==
-                   curl_easy_getinfo(curl, CURLINFO_SCHEME,
-                                     &stringp))
+                if((CURLE_OK == curl_easy_getinfo(curl, CURLINFO_SCHEME,
+                                                  &stringp)) && stringp)
                   fputs(stringp, stream);
                 break;
               case VAR_STDOUT: