@@ -451,8 +451,14 @@ static int winhttp_stream_connect(winhttp_stream *s)
451451 git_buf_puts (& processed_url , t -> proxy .url .scheme );
452452 git_buf_PUTS (& processed_url , "://" );
453453
454+ if (git_net_url_is_ipv6 (& t -> proxy .url ))
455+ git_buf_putc (& processed_url , '[' );
456+
454457 git_buf_puts (& processed_url , t -> proxy .url .host );
455458
459+ if (git_net_url_is_ipv6 (& t -> proxy .url ))
460+ git_buf_putc (& processed_url , ']' );
461+
456462 if (!git_net_url_is_default_port (& t -> proxy .url ))
457463 git_buf_printf (& processed_url , ":%s" , t -> proxy .url .port );
458464
@@ -736,10 +742,11 @@ static void CALLBACK winhttp_status(
736742static int winhttp_connect (
737743 winhttp_subtransport * t )
738744{
739- wchar_t * wide_host ;
745+ wchar_t * wide_host = NULL ;
740746 int32_t port ;
741- wchar_t * wide_ua ;
742- git_buf ua = GIT_BUF_INIT ;
747+ wchar_t * wide_ua = NULL ;
748+ git_buf ipv6 = GIT_BUF_INIT , ua = GIT_BUF_INIT ;
749+ const char * host ;
743750 int error = -1 ;
744751 int default_timeout = TIMEOUT_INFINITE ;
745752 int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT ;
@@ -755,29 +762,33 @@ static int winhttp_connect(
755762 /* Prepare port */
756763 if (git__strntol32 (& port , t -> server .url .port ,
757764 strlen (t -> server .url .port ), NULL , 10 ) < 0 )
758- return -1 ;
765+ goto on_error ;
766+
767+ /* IPv6? Add braces around the host. */
768+ if (git_net_url_is_ipv6 (& t -> server .url )) {
769+ if (git_buf_printf (& ipv6 , "[%s]" , t -> server .url .host ) < 0 )
770+ goto on_error ;
771+
772+ host = ipv6 .ptr ;
773+ } else {
774+ host = t -> server .url .host ;
775+ }
759776
760777 /* Prepare host */
761- if (git__utf8_to_16_alloc (& wide_host , t -> server . url . host ) < 0 ) {
778+ if (git__utf8_to_16_alloc (& wide_host , host ) < 0 ) {
762779 git_error_set (GIT_ERROR_OS , "unable to convert host to wide characters" );
763- return -1 ;
780+ goto on_error ;
764781 }
765782
766783
767- if ((error = git_http__user_agent (& ua )) < 0 ) {
768- git__free (wide_host );
769- return error ;
770- }
784+ if (git_http__user_agent (& ua ) < 0 )
785+ goto on_error ;
771786
772787 if (git__utf8_to_16_alloc (& wide_ua , git_buf_cstr (& ua )) < 0 ) {
773788 git_error_set (GIT_ERROR_OS , "unable to convert host to wide characters" );
774- git__free (wide_host );
775- git_buf_dispose (& ua );
776- return -1 ;
789+ goto on_error ;
777790 }
778791
779- git_buf_dispose (& ua );
780-
781792 /* Establish session */
782793 t -> session = WinHttpOpen (
783794 wide_ua ,
@@ -836,6 +847,7 @@ static int winhttp_connect(
836847 if (error < 0 )
837848 winhttp_close_connection (t );
838849
850+ git_buf_dispose (& ipv6 );
839851 git__free (wide_host );
840852 git__free (wide_ua );
841853
0 commit comments