]> git.sur5r.net Git - openldap/commitdiff
For IA5, printable, telephone:
authorKurt Zeilenga <kurt@openldap.org>
Tue, 6 Aug 2002 05:35:59 +0000 (05:35 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 6 Aug 2002 05:35:59 +0000 (05:35 +0000)
Don't allow empty string values.
Treat string values with only spaces as one space.
DirectoryString needs more work (space handling needs
to be done post normalization).

servers/slapd/schema_init.c

index 18051b6340bfcf3dea556b0352fbeb2d8f14b215..08fc1da9ed9d2caaf535f52f2b40a3f6813447ad 100644 (file)
@@ -619,6 +619,9 @@ UTF8StringNormalize(
        char *p, *q, *s, *e;
        int len = 0;
 
+       /* validator should have refused an empty string */
+       assert( val->bv_len );
+
        p = val->bv_val;
 
        /* Ignore initial whitespace */
@@ -626,6 +629,12 @@ UTF8StringNormalize(
        for ( ; p < val->bv_val + val->bv_len && ASCII_SPACE( p[ 0 ] ); p++ );
 
        normalized->bv_len = val->bv_len - (p - val->bv_val);
+
+       if( !normalized->bv_len ) {
+               ber_mem2bv( " ", 1, 1, normalized );
+               return LDAP_SUCCESS;
+       }
+
        ber_mem2bv( p, normalized->bv_len, 1, normalized );
        e = normalized->bv_val + normalized->bv_len;
 
@@ -1751,15 +1760,25 @@ telephoneNumberNormalize(
 {
        char *p, *q;
 
+       /* validator should have refused an empty string */
+       assert( val->bv_len );
+
        q = normalized->bv_val = ch_malloc( val->bv_len + 1 );
 
-       for( p = val->bv_val; *p; p++ )
-               if ( ! ( ASCII_SPACE( *p ) || *p == '-' ))
+       for( p = val->bv_val; *p; p++ ) {
+               if ( ! ( ASCII_SPACE( *p ) || *p == '-' )) {
                        *q++ = *p;
+               }
+       }
        *q = '\0';
 
        normalized->bv_len = q - normalized->bv_val;
 
+       if( normalized->bv_len == 0 ) {
+               free( normalized->bv_val );
+               return LDAP_INVALID_SYNTAX;
+       }
+
        return LDAP_SUCCESS;
 }
 
@@ -2061,6 +2080,8 @@ printableStringValidate(
 {
        ber_len_t i;
 
+       if( val->bv_len == 0 ) return LDAP_INVALID_SYNTAX;
+
        for(i=0; i < val->bv_len; i++) {
                if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
                        return LDAP_INVALID_SYNTAX;
@@ -2075,14 +2096,28 @@ printablesStringValidate(
        Syntax *syntax,
        struct berval *val )
 {
-       ber_len_t i;
+       ber_len_t i, len;
 
-       for(i=0; i < val->bv_len; i++) {
-               if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
+       if( val->bv_len == 0 ) return LDAP_INVALID_SYNTAX;
+
+       for(i=0,len=0; i < val->bv_len; i++) {
+               int c = val->bv_val[i];
+
+               if( c == '$' ) {
+                       if( len == 0 ) {
+                               return LDAP_INVALID_SYNTAX;
+                       }
+                       len = 0;
+
+               } else if ( SLAP_PRINTABLE(c) ) {
+                       len++;
+               } else {
                        return LDAP_INVALID_SYNTAX;
                }
        }
 
+       if( len == 0 ) LDAP_INVALID_SYNTAX;
+
        return LDAP_SUCCESS;
 }
 
@@ -2093,6 +2128,8 @@ IA5StringValidate(
 {
        ber_len_t i;
 
+       if( val->bv_len == 0 ) return LDAP_INVALID_SYNTAX;
+
        for(i=0; i < val->bv_len; i++) {
                if( !LDAP_ASCII(val->bv_val[i]) ) {
                        return LDAP_INVALID_SYNTAX;
@@ -2110,6 +2147,8 @@ IA5StringNormalize(
 {
        char *p, *q;
 
+       assert( val->bv_len );
+
        p = val->bv_val;
 
        /* Ignore initial whitespace */
@@ -2151,6 +2190,13 @@ IA5StringNormalize(
 
        normalized->bv_len = q - normalized->bv_val;
 
+       if( normalized->bv_len == 0 ) {
+               normalized->bv_val = ch_realloc( normalized->bv_val, 2 );
+               normalized->bv_val[0] = ' ';
+               normalized->bv_val[1] = '\0';
+               normalized->bv_len = 1;
+       }
+
        return LDAP_SUCCESS;
 }
 
@@ -3327,6 +3373,8 @@ numericStringValidate(
 {
        ber_len_t i;
 
+       if( in->bv_len == 0 ) return LDAP_INVALID_SYNTAX;
+
        for(i=0; i < in->bv_len; i++) {
                if( !SLAP_NUMERIC(in->bv_val[i]) ) {
                        return LDAP_INVALID_SYNTAX;
@@ -3345,6 +3393,8 @@ numericStringNormalize(
        /* removal all spaces */
        char *p, *q;
 
+       assert( val->bv_len );
+
        normalized->bv_val = ch_malloc( val->bv_len + 1 );
 
        p = val->bv_val;
@@ -3367,6 +3417,13 @@ numericStringNormalize(
 
        normalized->bv_len = q - normalized->bv_val;
 
+       if( normalized->bv_len == 0 ) {
+               normalized->bv_val = ch_realloc( normalized->bv_val, 2 );
+               normalized->bv_val[0] = ' ';
+               normalized->bv_val[1] = '\0';
+               normalized->bv_len = 1;
+       }
+
        return LDAP_SUCCESS;
 }