@@ -72,6 +72,19 @@ void aws_socks5_channel_handler_set_system_vtable(const struct aws_socks5_system
7272 }
7373}
7474
75+ /* SOCKS5 URIs follow RFC-3986, where IPv6 literals are enclosed in brackets.
76+ * DNS APIs expect bare literals, so strip a single leading '[' and trailing ']'. */
77+ static struct aws_byte_cursor s_normalize_proxy_host_cursor (struct aws_byte_cursor host_cursor ) {
78+ if (host_cursor .len >= 2 && host_cursor .ptr [0 ] == '[' ) {
79+ size_t last_index = host_cursor .len - 1 ;
80+ if (host_cursor .ptr [last_index ] == ']' ) {
81+ host_cursor .ptr += 1 ;
82+ host_cursor .len -= 2 ;
83+ }
84+ }
85+ return host_cursor ;
86+ }
87+
7588/**
7689 * State machine for the SOCKS5 channel handler
7790 *
@@ -119,26 +132,6 @@ static inline const char *s_socks5_channel_state_to_string(enum aws_socks5_chann
119132 }
120133}
121134
122- /**
123- * Returns a human-readable name for SOCKS5 message types used in logging.
124- * This aids in debugging by providing context about the type of message
125- * being processed in the SOCKS5 protocol.
126- */
127- static inline const char * s_get_socks5_message_type_name (int message_type ) {
128- switch (message_type ) {
129- case 0 :
130- return "INIT" ;
131- case 1 :
132- return "GREETING" ;
133- case 2 :
134- return "AUTH" ;
135- case 3 :
136- return "CONNECT" ;
137- default :
138- return "UNKNOWN" ;
139- }
140- }
141-
142135struct aws_socks5_channel_handler {
143136 /* Base handler data */
144137 struct aws_channel_handler handler ;
@@ -2889,6 +2882,7 @@ static int s_socks5_bootstrap_set_socks5_proxy_options(
28892882 }
28902883
28912884 struct aws_byte_cursor endpoint_host_cursor = aws_byte_cursor_from_c_str (host_name );
2885+ struct aws_byte_cursor normalized_host_cursor = s_normalize_proxy_host_cursor (endpoint_host_cursor );
28922886
28932887 aws_string_destroy (socks5_bootstrap -> endpoint_host );
28942888 socks5_bootstrap -> endpoint_host = NULL ;
@@ -2897,7 +2891,7 @@ static int s_socks5_bootstrap_set_socks5_proxy_options(
28972891
28982892 socks5_bootstrap -> endpoint_port = port ;
28992893 enum aws_socks5_address_type inferred_type =
2900- aws_socks5_infer_address_type (endpoint_host_cursor , AWS_SOCKS5_ATYP_DOMAIN );
2894+ aws_socks5_infer_address_type (normalized_host_cursor , AWS_SOCKS5_ATYP_DOMAIN );
29012895 socks5_bootstrap -> host_resolution_mode =
29022896 aws_socks5_proxy_options_get_host_resolution_mode (socks5_proxy_options );
29032897 socks5_bootstrap -> resolution_error_code = AWS_ERROR_SUCCESS ;
@@ -2908,7 +2902,7 @@ static int s_socks5_bootstrap_set_socks5_proxy_options(
29082902 if (socks5_bootstrap -> host_resolution_mode == AWS_SOCKS5_HOST_RESOLUTION_CLIENT &&
29092903 inferred_type != AWS_SOCKS5_ATYP_DOMAIN ) {
29102904 socks5_bootstrap -> endpoint_host =
2911- aws_string_new_from_cursor (allocator , & endpoint_host_cursor );
2905+ aws_string_new_from_cursor (allocator , & normalized_host_cursor );
29122906 if (!socks5_bootstrap -> endpoint_host ) {
29132907 aws_socks5_proxy_options_clean_up (socks5_proxy_options );
29142908 aws_mem_release (allocator , socks5_proxy_options );
@@ -2937,7 +2931,7 @@ static int s_socks5_bootstrap_set_socks5_proxy_options(
29372931 socks5_bootstrap -> endpoint_ready = false;
29382932 } else {
29392933 socks5_bootstrap -> endpoint_host =
2940- aws_string_new_from_cursor (allocator , & endpoint_host_cursor );
2934+ aws_string_new_from_cursor (allocator , & normalized_host_cursor );
29412935 if (!socks5_bootstrap -> endpoint_host ) {
29422936 aws_socks5_proxy_options_clean_up (socks5_proxy_options );
29432937 aws_mem_release (allocator , socks5_proxy_options );
0 commit comments