From: Pierangelo Masarati Date: Thu, 14 Feb 2002 18:55:38 +0000 (+0000) Subject: substrings match works with NULs in UTF8 strings X-Git-Tag: OPENLDAP_REL_ENG_2_1_BP~5 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=215448ac834be3c2efe75687dff05981c175ee0d;p=openldap substrings match works with NULs in UTF8 strings --- diff --git a/include/lber_pvt.h b/include/lber_pvt.h index d22c21b4ab..f03d4e8cb8 100644 --- a/include/lber_pvt.h +++ b/include/lber_pvt.h @@ -83,6 +83,9 @@ ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb )); #define ber_strccmp(s,c) \ ( (s)[0] == (c) && (s)[1] == '\0' ) +LBER_F( char * ) +ber_bvchr LDAP_P(( struct berval *bv, char c )); + LDAP_END_DECL #endif diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index b8692e1d57..6dbdea72c7 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -697,3 +697,26 @@ ber_bvarray_add( BerVarray *a, BerValue *bv ) return n; } + +char * +ber_bvchr( struct berval *bv, char c ) +{ + ber_len_t p; + + assert( bv ); + + if ( bv->bv_len == 0 ) { + return NULL; + } + + assert( bv->bv_val ); + + for ( p = 0; p < bv->bv_len; p++ ) { + if ( bv->bv_val[ p ] == c ) { + return &bv->bv_val[ p ]; + } + } + + return NULL; +} + diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index c46fbe54b1..1abba210b3 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -529,13 +529,7 @@ UTF8StringNormalize( /* Ignore initial whitespace */ /* All space is ASCII. All ASCII is 1 byte */ - while ( ASCII_SPACE( *p ) ) { - p++; - } - - if( *p == '\0' ) { - return LDAP_INVALID_SYNTAX; - } + for ( ; p < val->bv_val + val->bv_len && ASCII_SPACE( p[ 0 ] ); p++ ); ber_mem2bv( p, val->bv_len - (p - val->bv_val), 1, normalized ); e = normalized->bv_val + val->bv_len - (p - val->bv_val); @@ -1046,7 +1040,7 @@ caseExactIgnoreSubstringsMatch( struct berval left = { 0, NULL }; int i; ber_len_t inlen=0; - char *nav; + char *nav = NULL; unsigned casefold; casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID ) @@ -1083,7 +1077,7 @@ caseExactIgnoreSubstringsMatch( goto done; } - match = strncmp( sub->sa_initial.bv_val, left.bv_val, + match = memcmp( sub->sa_initial.bv_val, left.bv_val, sub->sa_initial.bv_len ); if( match != 0 ) { @@ -1101,7 +1095,7 @@ caseExactIgnoreSubstringsMatch( goto done; } - match = strncmp( sub->sa_final.bv_val, + match = memcmp( sub->sa_final.bv_val, &left.bv_val[left.bv_len - sub->sa_final.bv_len], sub->sa_final.bv_len ); @@ -1129,9 +1123,9 @@ retry: continue; } - p = strchr( left.bv_val, *sub->sa_any[i].bv_val ); + p = ber_bvchr( &left, *sub->sa_any[i].bv_val ); - if( p == NULL ) { + if ( p == NULL ) { match = 1; goto done; } @@ -1160,7 +1154,7 @@ retry: goto done; } - match = strncmp( left.bv_val, + match = memcmp( left.bv_val, sub->sa_any[i].bv_val, sub->sa_any[i].bv_len );