]> git.sur5r.net Git - openldap/commitdiff
define and use ber_strnlen() (ITS#6080); please regenerate configure and include...
authorPierangelo Masarati <ando@openldap.org>
Wed, 29 Apr 2009 11:38:31 +0000 (11:38 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 29 Apr 2009 11:38:31 +0000 (11:38 +0000)
configure.in
include/lber.h
libraries/liblber/memory.c

index 80975b82649e3e326a54555c4d49c9d044b96c1f..259dff7cb83fd1ffd25ff98cb3ac07499e60b3fe 100644 (file)
@@ -2480,6 +2480,7 @@ AC_CHECK_FUNCS(                   \
        seteuid                 \
        signal                  \
        strdup                  \
+       strnlen                 \
        strpbrk                 \
        strrchr                 \
        strsep                  \
index cbd2d64745d65dade93bcd5a2cbdb64852c88870..e3a8e668a8f3fe3802720ba297ff7e59f231bf40 100644 (file)
@@ -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 ));
index 6cf60ad284eaedd083b8607992a83a345b2f1b03..933b6fb7751e471fdcaeaaeed3e13e79dd1c3e35 100644 (file)
@@ -651,6 +651,24 @@ 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 )
+{
+#ifdef HAVE_STRNLEN
+       return (ber_len_t)strnlen( s, (ber_len_t)len );
+#else
+       ber_len_t l;
+
+       for ( l = 0; l < len; l++ ) {
+               if ( s[l] == '\0' ) {
+                       return l;
+               }
+       }
+
+       return len;
+#endif /* HAVE_STRNLEN */
+}
+
 char *
 ber_strndup_x( LDAP_CONST char *s, ber_len_t l, void *ctx )
 {
@@ -666,11 +684,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;