From: Quanah Gibson-Mount Date: Sat, 9 Feb 2008 00:51:52 +0000 (+0000) Subject: Declare enough buffer space for out-of-range URL port numbers X-Git-Tag: OPENLDAP_REL_ENG_2_4_8~125 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a93224fde26776056e7feaf22b98e99bbc3571c9;p=openldap Declare enough buffer space for out-of-range URL port numbers --- diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c index 4ef41f5ef4..882d21da30 100644 --- a/libraries/libldap/url.c +++ b/libraries/libldap/url.c @@ -582,19 +582,17 @@ desc2str_len( LDAPURLDesc *u ) len += sep; if ( u->lud_port ) { - char buf[ STRLENOF(":65535") + 1 ]; + unsigned p = u->lud_port; + if ( p > 65535 ) + return -1; - len += snprintf( buf, sizeof( buf ), ":%d", u->lud_port ); - if ( u->lud_host && u->lud_host[0] ) { - len += strlen( u->lud_host ); - } + len += (p > 999 ? 5 + (p > 9999) : p > 99 ? 4 : 2 + (p > 9)); + } - } else { - if ( u->lud_host && u->lud_host[0] ) { - len += hex_escape_len( u->lud_host, URLESC_SLASH ); - if ( !is_ipc && strchr( u->lud_host, ':' )) { - len += 2; /* IPv6, [] */ - } + if ( u->lud_host && u->lud_host[0] ) { + len += hex_escape_len( u->lud_host, URLESC_SLASH ); + if ( !is_ipc && strchr( u->lud_host, ':' )) { + len += 2; /* IPv6, [] */ } }