]> git.sur5r.net Git - openldap/commitdiff
Additional error checking + misc cleanup
authorKurt Zeilenga <kurt@openldap.org>
Wed, 2 Jan 2002 18:48:10 +0000 (18:48 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 2 Jan 2002 18:48:10 +0000 (18:48 +0000)
servers/slapd/str2filter.c

index 2f686094412988552c4542c1f583b3676c9af3ca..b4cd8466f2fdaf093d61c380b354f348e598a98f 100644 (file)
@@ -34,7 +34,6 @@ str2filter( const char *str )
        Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
 #endif
 
-
        if ( str == NULL || *str == '\0' ) {
                return( NULL );
        }
@@ -61,7 +60,6 @@ str2filter( const char *str )
                            0, 0, 0 );
 #endif
 
-
                        str++;
                        f = str2list( str, LDAP_FILTER_AND );
                        break;
@@ -75,7 +73,6 @@ str2filter( const char *str )
                            0, 0, 0 );
 #endif
 
-
                        str++;
                        f = str2list( str, LDAP_FILTER_OR );
                        break;
@@ -89,7 +86,6 @@ str2filter( const char *str )
                            0, 0, 0 );
 #endif
 
-
                        str++;
                        f = str2list( str, LDAP_FILTER_NOT );
                        break;
@@ -103,7 +99,6 @@ str2filter( const char *str )
                            0, 0, 0 );
 #endif
 
-
                        f = str2simple( str );
                        break;
                }
@@ -119,7 +114,6 @@ str2filter( const char *str )
                    0 );
 #endif
 
-
                f = str2simple( str );
                break;
        }
@@ -147,7 +141,6 @@ str2list( const char *str, unsigned long ftype )
        Debug( LDAP_DEBUG_FILTER, "str2list \"%s\"\n", str, 0, 0 );
 #endif
 
-
        f = (Filter *) ch_calloc( 1, sizeof(Filter) );
        f->f_choice = ftype;
        fp = &f->f_list;
@@ -197,9 +190,8 @@ str2simple( const char *str )
        Debug( LDAP_DEBUG_FILTER, "str2simple \"%s\"\n", str, 0, 0 );
 #endif
 
-
        if ( (s = strchr( str, '=' )) == NULL ) {
-               return( NULL );
+               return NULL;
        }
        value = &s[1];
 
@@ -249,10 +241,10 @@ str2simple( const char *str )
                                if ( str2subvals( value, f ) != 0 ) {
                                        filter_free( f );
                                        *(value-1) = '=';
-                                       return( NULL );
+                                       return NULL;
                                }
                                *(value-1) = '=';
-                               return( f );
+                               return f;
                        }
                } break;
        }
@@ -265,6 +257,7 @@ str2simple( const char *str )
                        return NULL;
                }
        } else {
+               ber_slen_t len;
                char *tmp;
 
                f->f_ava = ch_calloc( 1, sizeof( AttributeAssertion ) );
@@ -277,19 +270,26 @@ str2simple( const char *str )
                }
 
                tmp = ch_strdup( value );
-               ldap_pvt_filter_value_unescape( tmp );
+               len = ldap_pvt_filter_value_unescape( tmp );
+               if( len < 0 ) {
+                       filter_free( f );
+                       *(value-1) = '=';
+                       free( tmp );
+                       return -1;
+               }
                ber_str2bv( tmp, 0, 0, &f->f_av_value );
        }
 
        *s = savechar;
        *(value-1) = '=';
 
-       return( f );
+       return f;
 }
 
 static int
 str2subvals( const char *in, Filter *f )
 {
+       ber_slen_t len;
        char    *nextstar, *val, *freeme;
        int     gotstar;
        int final;
@@ -322,7 +322,11 @@ str2subvals( const char *in, Filter *f )
                        *nextstar = '\0';
                }
 
-               ldap_pvt_filter_value_unescape( val );
+               len = ldap_pvt_filter_value_unescape( val );
+               if( len < 0 ) {
+                       free( freeme );
+                       return -1;
+               }
 
                if ( final ) {
                        ber_str2bv( val, 0, 1, &f->f_sub_final );
@@ -331,14 +335,15 @@ str2subvals( const char *in, Filter *f )
                        ber_str2bv( val, 0, 1, &f->f_sub_initial );
 
                } else {
-                       charray_add( (char ***) &f->f_sub_any, (char *) ber_bvstrdup( val ) );
+                       charray_add( (char ***) &f->f_sub_any,
+                               (char *) ber_bvstrdup( val ) );
                }
 
                val = nextstar+1;
        }
 
        free( freeme );
-       return( 0 );
+       return 0;
 }
 
 /*