@@ -673,17 +673,25 @@ static const char *oidc_util_current_url_scheme(const request_rec *r, oidc_hdr_x
673673}
674674
675675/*
676- * get the port part from a Host header, taking into account IPv5 literal addresses
676+ * get the port from a Host or X-Forwarded-Host header
677677 */
678- static const char * oidc_util_port_from_host (const char * host_hdr ) {
678+ static const char * oidc_util_port_from_host_hdr (const char * host_hdr ) {
679679 const char * p = NULL ;
680680
681- if (host_hdr && host_hdr [0 ] == '[' )
681+ if (host_hdr == NULL )
682+ return NULL ;
683+
684+ // check for an IPv6 literal addresses
685+ if (host_hdr [0 ] == '[' )
682686 p = strchr (host_hdr , ']' );
683687 else
684688 p = host_hdr ;
685689
686- return p ? strchr (p , OIDC_CHAR_COLON ) : NULL ;
690+ if ((p = strchr (p , OIDC_CHAR_COLON )))
691+ // skip over the ":" to point to the actual port number
692+ p ++ ;
693+
694+ return p ;
687695}
688696
689697/*
@@ -715,25 +723,16 @@ static const char *oidc_get_current_url_port(const request_rec *r, const char *s
715723 if ((host_hdr == NULL ) && (x_forwarded_headers & OIDC_HDR_X_FORWARDED_HOST ))
716724 host_hdr = oidc_http_hdr_in_x_forwarded_host_get (r );
717725
718- if (host_hdr ) {
719- port_str = oidc_util_port_from_host (host_hdr );
720- if (port_str )
721- port_str ++ ;
722- return port_str ;
723- }
726+ if (host_hdr )
727+ return oidc_util_port_from_host_hdr (host_hdr );
724728
725729 /*
726730 * see if we can get the port from the "Host" header; if not
727731 * we'll determine the port locally
728732 */
729733 host_hdr = oidc_http_hdr_in_host_get (r );
730- if (host_hdr ) {
731- port_str = oidc_util_port_from_host (host_hdr );
732- if (port_str ) {
733- port_str ++ ;
734- return port_str ;
735- }
736- }
734+ if (host_hdr )
735+ return oidc_util_port_from_host_hdr (host_hdr );
737736
738737 /*
739738 * if X-Forwarded-Proto assume the default port otherwise the
0 commit comments