From: Norbert Lange Date: Fri, 12 Apr 2024 20:03:08 +0000 (+0200) Subject: PR31620: debuginfod-client.c: Test for https support in libcurl X-Git-Tag: elfutils-0.192~98 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=229aac471bb96035a4558db0dc74ff00d0aa08d1;p=thirdparty%2Felfutils.git PR31620: debuginfod-client.c: Test for https support in libcurl libcurl will fail if a protocol is requested that is not available. Signed-off-by: Norbert Lange --- diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 0ee7db3d..4e7a8a2a 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -115,11 +115,19 @@ void debuginfod_end (debuginfod_client *c) { } #include static pthread_once_t init_control = PTHREAD_ONCE_INIT; +static bool curl_has_https; // = false static void libcurl_init(void) { curl_global_init(CURL_GLOBAL_DEFAULT); + + for (const char *const *protocol = curl_version_info(CURLVERSION_NOW)->protocols; + *protocol != NULL; ++protocol) + { + if(strcmp("https", *protocol) == 0) + curl_has_https = true; + } } struct debuginfod_client @@ -1368,13 +1376,15 @@ debuginfod_query_server (debuginfod_client *c, } while (0) /* Only allow http:// + https:// + file:// so we aren't being - redirected to some unsupported protocol. */ + redirected to some unsupported protocol. + libcurl will fail if we request a single protocol that is not + available. https missing is the most likely issue */ #if CURL_AT_LEAST_VERSION(7, 85, 0) curl_easy_setopt_ck(data[i].handle, CURLOPT_PROTOCOLS_STR, - "http,https,file"); + curl_has_https ? "https,http,file" : "http,file"); #else curl_easy_setopt_ck(data[i].handle, CURLOPT_PROTOCOLS, - (CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FILE)); + ((curl_has_https ? CURLPROTO_HTTPS : 0) | CURLPROTO_HTTP | CURLPROTO_FILE)); #endif curl_easy_setopt_ck(data[i].handle, CURLOPT_URL, data[i].url); if (vfd >= 0)