]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_ipfs: check return codes better
authorDaniel Stenberg <daniel@haxx.se>
Thu, 6 Nov 2025 09:00:52 +0000 (10:00 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 6 Nov 2025 10:38:54 +0000 (11:38 +0100)
Closes #19382

src/tool_ipfs.c

index 8e98d23242ee2a28f371f74e5ca7795b03ae3aae..89d12fc1c6a53df6dc1aa38a86de7a668397785c 100644 (file)
@@ -165,23 +165,15 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url,
   }
 
   /* get gateway parts */
-  if(curl_url_get(gatewayurl, CURLUPART_HOST,
-                  &gwhost, CURLU_URLDECODE)) {
-    goto clean;
-  }
-
-  if(curl_url_get(gatewayurl, CURLUPART_SCHEME,
-                  &gwscheme, CURLU_URLDECODE)) {
-    goto clean;
-  }
-
-  curl_url_get(gatewayurl, CURLUPART_PORT, &gwport, CURLU_URLDECODE);
-
-  if(curl_url_get(gatewayurl, CURLUPART_PATH, &gwpath, CURLU_URLDECODE))
+  if(curl_url_get(gatewayurl, CURLUPART_HOST, &gwhost, CURLU_URLDECODE) ||
+     curl_url_get(gatewayurl, CURLUPART_SCHEME, &gwscheme, CURLU_URLDECODE) ||
+     curl_url_get(gatewayurl, CURLUPART_PORT, &gwport, CURLU_URLDECODE) ||
+     curl_url_get(gatewayurl, CURLUPART_PATH, &gwpath, CURLU_URLDECODE))
     goto clean;
 
   /* get the path from user input */
-  curl_url_get(uh, CURLUPART_PATH, &inputpath, CURLU_URLDECODE);
+  if(curl_url_get(uh, CURLUPART_PATH, &inputpath, CURLU_URLDECODE))
+    goto clean;
   /* inputpath might be NULL or a valid pointer now */
 
   /* set gateway parts in input url */
@@ -198,13 +190,9 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url,
                              has_trailing_slash(gwpath) ? "" : "/",
                              protocol, cid,
                              inputpath ? inputpath : "");
-  if(!pathbuffer) {
-    goto clean;
-  }
-
-  if(curl_url_set(uh, CURLUPART_PATH, pathbuffer, CURLU_URLENCODE)) {
+  if(!pathbuffer ||
+     curl_url_set(uh, CURLUPART_PATH, pathbuffer, CURLU_URLENCODE))
     goto clean;
-  }
 
   /* Free whatever it has now, rewriting is next */
   tool_safefree(*url);