]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_operate: fix a case of ignoring return code in operate()
authorDaniel Stenberg <daniel@haxx.se>
Sat, 22 Nov 2025 18:09:42 +0000 (19:09 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 22 Nov 2025 21:22:41 +0000 (22:22 +0100)
If get_args() returns error, do not overwrite the variable in the next
call.

Also, avoid allocating memory for the default user-agent.

Closes #19650

src/config2setopts.c
src/tool_operate.c
src/tool_paramhlp.c

index 154319231f11cf5a1a4b9f611a2e5661181ec2ee..d3bd39c8647c1464c89da5150312966712fc832b 100644 (file)
@@ -37,6 +37,7 @@
 #include "tool_cb_see.h"
 #include "tool_cb_dbg.h"
 #include "tool_helpers.h"
+#include "tool_version.h"
 
 #define BUFFER_SIZE 102400L
 
@@ -874,7 +875,8 @@ CURLcode config2setopts(struct OperationConfig *config,
 
   if(proto_http || proto_rtsp) {
     MY_SETOPT_STR(curl, CURLOPT_REFERER, config->referer);
-    MY_SETOPT_STR(curl, CURLOPT_USERAGENT, config->useragent);
+    MY_SETOPT_STR(curl, CURLOPT_USERAGENT, config->useragent ?
+                  config->useragent : CURL_NAME "/" CURL_VERSION);
   }
 
   if(use_proto == proto_http || use_proto == proto_https) {
index eea5ff37a2602968788b852860243fa052a8a659..69cfef96d78617f819d1eb671f8e9377a38d6a38 100644 (file)
@@ -2321,17 +2321,19 @@ CURLcode operate(int argc, argv_item_t argv[])
             operation = operation->next;
           } while(!result && operation);
 
-          /* Set the current operation pointer */
-          global->current = global->first;
-
-          /* now run! */
-          result = run_all_transfers(share, result);
-
-          if(global->ssl_sessions && feature_ssls_export) {
-            CURLcode r2 = tool_ssls_save(global->first, share,
-                                         global->ssl_sessions);
-            if(r2 && !result)
-              result = r2;
+          if(!result) {
+            /* Set the current operation pointer */
+            global->current = global->first;
+
+            /* now run! */
+            result = run_all_transfers(share, result);
+
+            if(global->ssl_sessions && feature_ssls_export) {
+              CURLcode r2 = tool_ssls_save(global->first, share,
+                                           global->ssl_sessions);
+              if(r2 && !result)
+                result = r2;
+            }
           }
         }
 
index 2e7b98f26eb064be9121cfb72c9c7f4faf9bce0b..15293c0cc6ce23a93ba1b927c07ff78ba1eab840 100644 (file)
@@ -650,14 +650,6 @@ long delegation(const char *str)
   return CURLGSSAPI_DELEGATION_NONE;
 }
 
-/*
- * my_useragent: returns allocated string with default user agent
- */
-static char *my_useragent(void)
-{
-  return strdup(CURL_NAME "/" CURL_VERSION);
-}
-
 #define isheadersep(x) ((((x)==':') || ((x)==';')))
 
 /*
@@ -705,15 +697,6 @@ CURLcode get_args(struct OperationConfig *config, const size_t i)
   if(!result && config->proxyuserpwd)
     result = checkpasswd("proxy", i, last, &config->proxyuserpwd);
 
-  /* Check if we have a user agent */
-  if(!result && !config->useragent) {
-    config->useragent = my_useragent();
-    if(!config->useragent) {
-      errorf("out of memory");
-      result = CURLE_OUT_OF_MEMORY;
-    }
-  }
-
   return result;
 }