From: Daniel Stenberg Date: Thu, 13 Nov 2025 15:26:24 +0000 (+0100) Subject: tool_operate: exit on curl_share_setopt errors X-Git-Tag: rc-8_18_0-1~308 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75955c0851cba958aa0f3137312ecb2a06f282a2;p=thirdparty%2Fcurl.git tool_operate: exit on curl_share_setopt errors Continuing when one of these has failed is fragile and error-prone. Closes #19513 --- diff --git a/src/tool_operate.c b/src/tool_operate.c index 2c85839d17..9aee520f06 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -2200,6 +2200,36 @@ static CURLcode run_all_transfers(CURLSH *share, return result; } +static CURLcode share_setopt(CURLSH *share, int opt) +{ + CURLSHcode shres = curl_share_setopt(share, CURLSHOPT_SHARE, opt); + if(!shres || (shres == CURLSHE_NOT_BUILT_IN)) + return CURLE_OK; + return CURLE_FAILED_INIT; +} + +static CURLcode share_setup(CURLSH *share) +{ + CURLcode result = CURLE_OK; + int i; + static int options[7] = { + CURL_LOCK_DATA_COOKIE, + CURL_LOCK_DATA_DNS, + CURL_LOCK_DATA_SSL_SESSION, + CURL_LOCK_DATA_PSL, + CURL_LOCK_DATA_HSTS, + 0, /* 5 might be set below */ + 0 + }; + /* Running parallel, use the multi connection cache */ + if(!global->parallel) + options[5] = CURL_LOCK_DATA_CONNECT; + for(i = 0; !result && options[i]; i++) + result = share_setopt(share, options[i]); + return result; +} + + CURLcode operate(int argc, argv_item_t argv[]) { CURLcode result = CURLE_OK; @@ -2286,52 +2316,43 @@ CURLcode operate(int argc, argv_item_t argv[]) result = CURLE_OUT_OF_MEMORY; } + if(!result) + result = share_setup(share); + + if(!result && global->ssl_sessions && feature_ssls_export) + result = tool_ssls_load(global->first, share, + global->ssl_sessions); + if(!result) { - curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE); - curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); - curl_share_setopt(share, CURLSHOPT_SHARE, - CURL_LOCK_DATA_SSL_SESSION); - /* Running parallel, use the multi connection cache */ - if(!global->parallel) - curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); - curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL); - curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS); - - if(global->ssl_sessions && feature_ssls_export) - result = tool_ssls_load(global->first, share, - global->ssl_sessions); - - if(!result) { - /* Get the required arguments for each operation */ - do { - result = get_args(operation, count++); - - 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; - } - } + /* Get the required arguments for each operation */ + do { + result = get_args(operation, count++); - curl_share_cleanup(share); - if(global->libcurl) { - /* Cleanup the libcurl source output */ - easysrc_cleanup(); + operation = operation->next; + } while(!result && operation); - /* Dump the libcurl code if previously enabled */ - dumpeasysrc(); + /* 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; } } + + curl_share_cleanup(share); + if(global->libcurl) { + /* Cleanup the libcurl source output */ + easysrc_cleanup(); + + /* Dump the libcurl code if previously enabled */ + dumpeasysrc(); + } } else errorf("out of memory");