@@ -987,17 +987,39 @@ static http_profile_t *url_cache_http_profile_find_by_fqdn(url_cache_t *cache, c
987987 }
988988
989989 switch_copy_string (host , fqdn , DOMAIN_BUF_SIZE );
990- port = strchr (host , ':' );
991- if (port ) {
992- if (host [0 ] == '[' ) {
993- /* IPv6 with port - find closing bracket */
994- char * bracket = strchr (host , ']' );
995- if (bracket && bracket [1 ] == ':' ) {
996- memmove (host , host + 1 , bracket - host );
997- host [bracket - host - 1 ] = '\0' ;
998- }
990+
991+ /* Handle IPv6 addresses with brackets */
992+ if (host [0 ] == '[' ) {
993+ char * bracket_close = strchr (host , ']' );
994+ if (!bracket_close ) {
995+ switch_log_printf (SWITCH_CHANNEL_LOG , SWITCH_LOG_WARNING ,
996+ "Malformed IPv6 address in URL '%s': opening bracket '[' without closing bracket ']'\n" , fqdn );
997+ return NULL ;
998+ }
999+
1000+ if (bracket_close [1 ] == ':' ) {
1001+ memmove (host , host + 1 , bracket_close - host - 1 );
1002+ host [bracket_close - host - 1 ] = '\0' ;
1003+ } else if (bracket_close [1 ] == '\0' ) {
1004+ memmove (host , host + 1 , bracket_close - host - 1 );
1005+ host [bracket_close - host - 1 ] = '\0' ;
9991006 } else {
1000- /* IPv4 with port, or IPv6 without brackets */
1007+ switch_log_printf (SWITCH_CHANNEL_LOG , SWITCH_LOG_WARNING ,
1008+ "Malformed IPv6 address in URL '%s': invalid character '%c' after closing bracket ']'\n" ,
1009+ fqdn , bracket_close [1 ]);
1010+ return NULL ;
1011+ }
1012+ } else {
1013+ /* IPv4 with port, or IPv6 without brackets */
1014+ char * bracket_close = strchr (host , ']' );
1015+ if (bracket_close ) {
1016+ switch_log_printf (SWITCH_CHANNEL_LOG , SWITCH_LOG_WARNING ,
1017+ "Malformed IPv6 address in URL '%s': closing bracket ']' without opening bracket '['\n" , fqdn );
1018+ return NULL ;
1019+ }
1020+
1021+ port = strchr (host , ':' );
1022+ if (port ) {
10011023 int colon_count = 0 ;
10021024 char * p ;
10031025 for (p = host ; * p ; p ++ ) {
0 commit comments