Skip to content

Commit aeae4db

Browse files
bmwillgitster
authored andcommitted
http: create function to get curl allowed protocols
Move the creation of an allowed protocols whitelist to a helper function. This will be useful when we need to compute the set of allowed protocols differently for normal and redirect cases. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f1762d7 commit aeae4db

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

http.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,25 @@ static void set_curl_keepalive(CURL *c)
489489
}
490490
#endif
491491

492+
static long get_curl_allowed_protocols(void)
493+
{
494+
long allowed_protocols = 0;
495+
496+
if (is_transport_allowed("http"))
497+
allowed_protocols |= CURLPROTO_HTTP;
498+
if (is_transport_allowed("https"))
499+
allowed_protocols |= CURLPROTO_HTTPS;
500+
if (is_transport_allowed("ftp"))
501+
allowed_protocols |= CURLPROTO_FTP;
502+
if (is_transport_allowed("ftps"))
503+
allowed_protocols |= CURLPROTO_FTPS;
504+
505+
return allowed_protocols;
506+
}
507+
492508
static CURL *get_curl_handle(void)
493509
{
494510
CURL *result = curl_easy_init();
495-
long allowed_protocols = 0;
496511

497512
if (!result)
498513
die("curl_easy_init failed");
@@ -572,16 +587,10 @@ static CURL *get_curl_handle(void)
572587
curl_easy_setopt(result, CURLOPT_POST301, 1);
573588
#endif
574589
#if LIBCURL_VERSION_NUM >= 0x071304
575-
if (is_transport_allowed("http"))
576-
allowed_protocols |= CURLPROTO_HTTP;
577-
if (is_transport_allowed("https"))
578-
allowed_protocols |= CURLPROTO_HTTPS;
579-
if (is_transport_allowed("ftp"))
580-
allowed_protocols |= CURLPROTO_FTP;
581-
if (is_transport_allowed("ftps"))
582-
allowed_protocols |= CURLPROTO_FTPS;
583-
curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS, allowed_protocols);
584-
curl_easy_setopt(result, CURLOPT_PROTOCOLS, allowed_protocols);
590+
curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS,
591+
get_curl_allowed_protocols());
592+
curl_easy_setopt(result, CURLOPT_PROTOCOLS,
593+
get_curl_allowed_protocols());
585594
#else
586595
warning("protocol restrictions not applied to curl redirects because\n"
587596
"your curl version is too old (>= 7.19.4)");

0 commit comments

Comments
 (0)