]> git.sur5r.net Git - openldap/commitdiff
substrings match works with NULs in UTF8 strings
authorPierangelo Masarati <ando@openldap.org>
Thu, 14 Feb 2002 18:55:38 +0000 (18:55 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 14 Feb 2002 18:55:38 +0000 (18:55 +0000)
include/lber_pvt.h
libraries/liblber/memory.c
servers/slapd/schema_init.c

index d22c21b4abef8e3453fe25dac6981ac71a1fbdfc..f03d4e8cb8c78cb36c485123931405686d012c08 100644 (file)
@@ -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
index b8692e1d576d19f1652715645628e261351212a0..6dbdea72c7f904d7b14d07a4cf44021b1a98b9c2 100644 (file)
@@ -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;
+}
+
index c46fbe54b11e4d8b167f4546b3d16d5f07206bda..1abba210b38068aa2340d559a2a3dfe7b17ba35d 100644 (file)
@@ -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 );