]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_operate: avoid strlen() -1 on zero length content from file
authorDaniel Stenberg <daniel@haxx.se>
Wed, 27 Sep 2023 08:27:07 +0000 (10:27 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 28 Sep 2023 07:24:57 +0000 (09:24 +0200)
Follow-up to 65b563a96a226649ba12cb1e

Closes #11959

src/tool_operate.c

index 29249975a4ab0f7233d4cc8e29c452faa08e4fc9..19d55ba569c437ce5a228b93c991068639880d57 100644 (file)
@@ -749,14 +749,13 @@ static char *ipfs_gateway(void)
   Curl_safefree(gateway_composed_file_path);
 
   if(gateway_file) {
-    char *gateway_buffer = NULL;
+    char *buf = NULL;
 
-    if((PARAM_OK == file2string(&gateway_buffer, gateway_file)) &&
-       gateway_buffer) {
-      bool add_slash = (gateway_buffer[strlen(gateway_buffer) - 1] != '/');
-      gateway = aprintf("%s%s", gateway_buffer, (add_slash) ? "/" : "");
-      Curl_safefree(gateway_buffer);
+    if((PARAM_OK == file2string(&buf, gateway_file)) && buf && *buf) {
+      bool add_slash = (buf[strlen(buf) - 1] != '/');
+      gateway = aprintf("%s%s", buf, (add_slash) ? "/" : "");
     }
+    Curl_safefree(buf);
 
     if(gateway_file)
       fclose(gateway_file);