From: Daniel Stenberg Date: Thu, 24 Oct 2024 13:49:51 +0000 (+0200) Subject: curl: detect ECH support dynamically, not at build time X-Git-Tag: curl-8_11_0~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=469f53686a76a980270a06d8addc5b3a496eaa0b;p=thirdparty%2Fcurl.git curl: detect ECH support dynamically, not at build time Closes #15402 --- diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c index 48808adb27..d7ee7b1b22 100644 --- a/src/tool_cfgable.c +++ b/src/tool_cfgable.c @@ -173,21 +173,14 @@ static void free_config_fields(struct OperationConfig *config) Curl_safefree(config->preproxy); Curl_safefree(config->proxy_service_name); Curl_safefree(config->service_name); - Curl_safefree(config->ftp_account); Curl_safefree(config->ftp_alternative_to_user); - Curl_safefree(config->aws_sigv4); Curl_safefree(config->proto_str); Curl_safefree(config->proto_redir_str); -#ifdef USE_ECH Curl_safefree(config->ech); - config->ech = NULL; Curl_safefree(config->ech_config); - config->ech_config = NULL; Curl_safefree(config->ech_public); - config->ech_public = NULL; -#endif } void config_free(struct OperationConfig *config) diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h index 257a8d2c66..46f47670d6 100644 --- a/src/tool_cfgable.h +++ b/src/tool_cfgable.h @@ -306,12 +306,9 @@ struct OperationConfig { bool rm_partial; /* on error, remove partially written output files */ bool skip_existing; -#ifdef USE_ECH char *ech; /* Config set by --ech keywords */ char *ech_config; /* Config set by "--ech esl:" option */ char *ech_public; /* Config set by "--ech pn:" option */ -#endif - }; struct GlobalConfig { diff --git a/src/tool_getparam.c b/src/tool_getparam.c index da42a4f62d..0ce790f30a 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -1917,13 +1917,10 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ err = PARAM_ENGINES_REQUESTED; } break; -#ifndef USE_ECH - case C_ECH: /* --ech, not implemented by default */ - err = PARAM_LIBCURL_DOESNT_SUPPORT; - break; -#else case C_ECH: /* --ech */ - if(strlen(nextarg) > 4 && strncasecompare("pn:", nextarg, 3)) { + if(!feature_ech) + err = PARAM_LIBCURL_DOESNT_SUPPORT; + else if(strlen(nextarg) > 4 && strncasecompare("pn:", nextarg, 3)) { /* a public_name */ err = getstr(&config->ech_public, nextarg, DENY_BLANK); } @@ -1967,7 +1964,6 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ err = getstr(&config->ech, nextarg, DENY_BLANK); } break; -#endif case C_CAPATH: /* --capath */ err = getstr(&config->capath, nextarg, DENY_BLANK); break; diff --git a/src/tool_libinfo.c b/src/tool_libinfo.c index 34b79f5eb7..f6053e8400 100644 --- a/src/tool_libinfo.c +++ b/src/tool_libinfo.c @@ -83,6 +83,7 @@ bool feature_spnego = FALSE; bool feature_ssl = FALSE; bool feature_tls_srp = FALSE; bool feature_zstd = FALSE; +bool feature_ech = FALSE; static struct feature_name_presentp { const char *feature_name; @@ -95,6 +96,7 @@ static struct feature_name_presentp { {"brotli", &feature_brotli, CURL_VERSION_BROTLI}, {"CharConv", NULL, CURL_VERSION_CONV}, {"Debug", NULL, CURL_VERSION_DEBUG}, + {"ECH", &feature_ech, 0}, {"gsasl", NULL, CURL_VERSION_GSASL}, {"GSS-API", NULL, CURL_VERSION_GSSAPI}, {"HSTS", &feature_hsts, CURL_VERSION_HSTS}, diff --git a/src/tool_libinfo.h b/src/tool_libinfo.h index ad9c195dc0..0d176699e8 100644 --- a/src/tool_libinfo.h +++ b/src/tool_libinfo.h @@ -61,6 +61,7 @@ extern bool feature_spnego; extern bool feature_ssl; extern bool feature_tls_srp; extern bool feature_zstd; +extern bool feature_ech; CURLcode get_libcurl_info(void); const char *proto_token(const char *proto); diff --git a/src/tool_operate.c b/src/tool_operate.c index fd10e39ba0..b98ec01394 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -1734,15 +1734,15 @@ static CURLcode config2setopts(struct GlobalConfig *global, if(config->hsts) my_setopt_str(curl, CURLOPT_HSTS, config->hsts); -#ifdef USE_ECH - /* only if enabled in configure */ - if(config->ech) /* only if set (optional) */ - my_setopt_str(curl, CURLOPT_ECH, config->ech); - if(config->ech_public) /* only if set (optional) */ - my_setopt_str(curl, CURLOPT_ECH, config->ech_public); - if(config->ech_config) /* only if set (optional) */ - my_setopt_str(curl, CURLOPT_ECH, config->ech_config); -#endif + if(feature_ech) { + /* only if enabled in libcurl */ + if(config->ech) /* only if set (optional) */ + my_setopt_str(curl, CURLOPT_ECH, config->ech); + if(config->ech_public) /* only if set (optional) */ + my_setopt_str(curl, CURLOPT_ECH, config->ech_public); + if(config->ech_config) /* only if set (optional) */ + my_setopt_str(curl, CURLOPT_ECH, config->ech_config); + } /* new in 8.9.0 */ if(config->ip_tos > 0 || config->vlan_priority > 0) {