From 8e6d927ab9d450c2d38d41a8f84a204faef82022 Mon Sep 17 00:00:00 2001 From: Quanah Gibson-Mount Date: Fri, 1 May 2009 21:28:56 +0000 Subject: [PATCH] ITS#6080 --- CHANGES | 2 +- include/lber.h | 8 ++++++++ libraries/liblber/memory.c | 16 +++++++++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 3be2095248..5431c3aa61 100644 --- a/CHANGES +++ b/CHANGES @@ -3,7 +3,7 @@ OpenLDAP 2.4 Change Log OpenLDAP 2.4.17 Engineering Fixed libldap gnutls private key init (ITS#6053) Fixed liblutil opendir/closedir on windows (ITS#6041) - Fixed liblutil for _GNU_SOURCE (ITS#5464,ITS#5666) + Fixed liblutil to use ber_strnlen (ITS#5464,ITS#5666,ITS#6080) Fixed slapd errno handling (ITS#6037) Fixed slapd global alloc handling (ITS#6054) Fixed slapd moduleload with static backends and modules (ITS#6016) diff --git a/include/lber.h b/include/lber.h index cbd2d64745..e3a8e668a8 100644 --- a/include/lber.h +++ b/include/lber.h @@ -629,6 +629,14 @@ LBER_F( char * ) ber_strdup LDAP_P(( LDAP_CONST char * )); +LBER_F( ber_len_t ) +ber_strnlen LDAP_P(( + LDAP_CONST char *s, ber_len_t len )); + +LBER_F( char * ) +ber_strndup LDAP_P(( + LDAP_CONST char *s, ber_len_t l )); + LBER_F( struct berval * ) ber_bvreplace LDAP_P(( struct berval *dst, LDAP_CONST struct berval *src )); diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index 6cf60ad284..284cd04b8e 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -651,6 +651,16 @@ ber_strdup( LDAP_CONST char *s ) return ber_strdup_x( s, NULL ); } +ber_len_t +ber_strnlen( LDAP_CONST char *s, ber_len_t len ) +{ + ber_len_t l; + + for ( l = 0; l < len && s[l] != '\0'; l++ ) ; + + return l; +} + char * ber_strndup_x( LDAP_CONST char *s, ber_len_t l, void *ctx ) { @@ -666,11 +676,7 @@ ber_strndup_x( LDAP_CONST char *s, ber_len_t l, void *ctx ) return NULL; } - len = strlen( s ); - - if ( len > l ) { - len = l; - } + len = ber_strnlen( s, l ); if ( (p = ber_memalloc_x( len + 1, ctx )) == NULL ) { ber_errno = LBER_ERROR_MEMORY; -- 2.39.5