]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
malloc fixes and other misc cleanup
authorKurt Zeilenga <kurt@openldap.org>
Tue, 26 Nov 2002 19:26:19 +0000 (19:26 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 26 Nov 2002 19:26:19 +0000 (19:26 +0000)
servers/slapd/mods.c
servers/slapd/mr.c
servers/slapd/oc.c
servers/slapd/oidm.c
servers/slapd/referral.c
servers/slapd/sasl.c
servers/slapd/schema_init.c
servers/slapd/sets.c
servers/slapd/str2filter.c
servers/slapd/value.c

index 403ee8e9bd9600aacd7857bed07c87f98a301414..4b1166d2847bf394c2485d4caea6e90056ea93dc 100644 (file)
@@ -29,7 +29,7 @@ modify_check_duplicates(
 {
        int             i, j, numvals = 0, nummods,
                        rc = LDAP_SUCCESS;
-       BerVarray       nvals = NULL, nmods;
+       BerVarray       nvals = NULL, nmods = NULL;
 
        /*
         * FIXME: better do the following
@@ -73,7 +73,17 @@ modify_check_duplicates(
                        /* count existing values */ ;
 
                if ( numvals < nummods ) {
-                       nvals = ch_calloc( numvals + 1, sizeof( struct berval ) );
+                       nvals = SLAP_CALLOC( numvals + 1, sizeof( struct berval ) );
+                       if( nvals == NULL ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG( OPERATION, ERR,
+                                       "modify_check_duplicates: SLAP_CALLOC failed", 0, 0, 0 );
+#else
+                               Debug( LDAP_DEBUG_ANY, 
+                                       "modify_check_duplicates: SLAP_CALLOC failed", 0, 0, 0 );
+#endif
+                               goto return_results;
+                       }
 
                        /* normalize the existing values first */
                        for ( j = 0; vals[ j ].bv_val != NULL; j++ ) {
@@ -98,7 +108,17 @@ modify_check_duplicates(
         * values and test each new value against them first,
         * then to other already normalized values
         */
-       nmods = ch_calloc( nummods + 1, sizeof( struct berval ) );
+       nmods = SLAP_CALLOC( nummods + 1, sizeof( struct berval ) );
+       if ( nmods == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, ERR,
+                       "modify_check_duplicates: SLAP_CALLOC failed", 0, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY, 
+                       "modify_check_duplicates: SLAP_CALLOC failed", 0, 0, 0 );
+#endif
+               goto return_results;
+       }
 
        for ( i = 0; mods[ i ].bv_val != NULL; i++ ) {
                rc = value_normalize( ad, SLAP_MR_EQUALITY,
@@ -430,7 +450,17 @@ modify_delete_values(
        for ( j = 0; a->a_vals[ j ].bv_val != NULL; j++ )
                /* count existing values */ ;
 
-       nvals = (BerVarray)ch_calloc( j + 1, sizeof ( struct berval ) );
+       nvals = (BerVarray)SLAP_CALLOC( j + 1, sizeof ( struct berval ) );
+       if( nvals == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, ERR,
+                       "modify_delete_values: SLAP_CALLOC failed", 0, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY, 
+                       "modify_delete_values: SLAP_CALLOC failed", 0, 0, 0 );
+#endif
+                               goto return_results;
+       }
 
        /* normalize existing values */
        for ( j = 0; a->a_vals[ j ].bv_val != NULL; j++ ) {
index 64d02b30581fd51d806e7289d3eaceafc7c67aae..58e5c960a43532460c674c20db74a8175cbd7f71 100644 (file)
@@ -310,16 +310,6 @@ matching_rule_use_init( void )
        MatchingRule    *mr;
        MatchingRuleUse **mru_ptr = &mru_list;
 
-#define MR_TYPE_MASK           ( SLAP_MR_TYPE_MASK & ~SLAP_MR_EXT )
-#define MR_TYPE_SUBTYPE_MASK   ( MR_TYPE_MASK | SLAP_MR_SUBTYPE_MASK ) 
-#if 0  /* all types regardless of EXT */
-#define MR_TYPE(x)             ( (x) & MR_TYPE_MASK )
-#define MR_TYPE_SUBTYPE(x)     ( (x) & MR_TYPE_SUBTYPE_MASK )
-#else  /* only those marked as EXT (as per RFC 2252) */
-#define MR_TYPE(x)             ( ( (x) & SLAP_MR_EXT ) ? ( (x) & MR_TYPE_MASK ) : SLAP_MR_NONE )
-#define MR_TYPE_SUBTYPE(x)     ( ( (x) & SLAP_MR_EXT ) ? ( (x) & MR_TYPE_SUBTYPE_MASK ) : SLAP_MR_NONE )
-#endif
-
 #ifdef NEW_LOGGING
        LDAP_LOG( OPERATION, INFO, "matching_rule_use_init\n", 0, 0, 0 );
 #else
@@ -327,9 +317,6 @@ matching_rule_use_init( void )
 #endif
 
        for ( mr = mr_list; mr; mr = mr->smr_next ) {
-               slap_mask_t     um = MR_TYPE( mr->smr_usage );
-               slap_mask_t     usm = MR_TYPE_SUBTYPE( mr->smr_usage );
-
                AttributeType   *at;
                MatchingRuleUse _mru, *mru = &_mru;
 
index 4ce2b8b66abf4a76aefe072a2a3da248a9e0928f..8dbe1b29ead02a0b4c8252f0ee3883fc1a2426a9 100644 (file)
@@ -67,7 +67,7 @@ int is_entry_objectclass(
        }
 
        if( set_flags && ( e->e_ocflags & SLAP_OC__END )) {
-               return (e->e_ocflags & oc->soc_flags) ? 1 : 0;
+               return (e->e_ocflags & oc->soc_flags) == oc->soc_flags;
        }
 
        /*
@@ -105,7 +105,7 @@ int is_entry_objectclass(
        }
        e->e_ocflags |= SLAP_OC__END;   /* We've finished this */
 
-       return (e->e_ocflags & oc->soc_flags);
+       return (e->e_ocflags & oc->soc_flags) == oc->soc_flags;
 }
 
 
index a244d18b9b223fbf51cb6db0b33d6bc0f82c10c4..4075171d13f18169c89b35fe0c5aedb5d483c0e1 100644 (file)
@@ -43,8 +43,18 @@ oidm_find(char *oid)
 
                        if( pos ) {
                                int suflen = strlen(oid + pos);
-                               char *tmp = ch_malloc( om->som_oid.bv_len
+                               char *tmp = SLAP_MALLOC( om->som_oid.bv_len
                                        + suflen + 1);
+                               if( tmp == NULL ) {
+#ifdef NEW_LOGGING
+                                       LDAP_LOG( OPERATION, ERR,
+                                               "oidm_find: SLAP_MALLOC failed", 0, 0, 0 );
+#else
+                                       Debug( LDAP_DEBUG_ANY,
+                                               "oidm_find: SLAP_MALLOC failed", 0, 0, 0 );
+#endif
+                                       return NULL;
+                               }
                                strcpy(tmp, om->som_oid.bv_val);
                                if( suflen ) {
                                        suflen = om->som_oid.bv_len;
@@ -98,7 +108,15 @@ usage:      fprintf( stderr, "\tObjectIdentifier <name> <oid>\n");
                return 1;
        }
 
-       om = (OidMacro *) ch_malloc( sizeof(OidMacro) );
+       om = (OidMacro *) SLAP_MALLOC( sizeof(OidMacro) );
+       if( om == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, ERR, "parse_oidm: SLAP_MALLOC failed", 0, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY, "parse_oidm: SLAP_MALLOC failed", 0, 0, 0 );
+#endif
+               return 1;
+       }
 
        om->som_names = NULL;
        ldap_charray_add( &om->som_names, argv[1] );
index e9b187a734c76bf5bff6283ee882cae4cdf66a38..57a46713a50571e025f7ab01fd474fe1af878ec0 100644 (file)
@@ -101,7 +101,17 @@ static char * referral_dn_muck(
                        }
 
                        muck.bv_len = ntargetDN.bv_len + nrefDN.bv_len - nbaseDN.bv_len;
-                       muck.bv_val = ch_malloc( muck.bv_len + 1 );
+                       muck.bv_val = SLAP_MALLOC( muck.bv_len + 1 );
+                       if( muck.bv_val == NULL ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG( OPERATION, CRIT, 
+                                       "referral_dn_muck: SLAP_MALLOC failed\n", 0, 0, 0 );
+#else
+                               Debug( LDAP_DEBUG_ANY,
+                                       "referral_dn_muck: SLAP_MALLOC failed\n", 0, 0, 0 );
+#endif
+                               return NULL;
+                       }
 
                        strncpy( muck.bv_val, ntargetDN.bv_val,
                                ntargetDN.bv_len-nbaseDN.bv_len );
@@ -225,7 +235,17 @@ BerVarray referral_rewrite(
 
        if( i < 1 ) return NULL;
 
-       refs = ch_malloc( (i+1) * sizeof( struct berval ) );
+       refs = SLAP_MALLOC( (i+1) * sizeof( struct berval ) );
+       if( refs == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT, 
+                       "referral_rewrite: SLAP_MALLOC failed\n", 0, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "referral_rewrite: SLAP_MALLOC failed\n", 0, 0, 0 );
+#endif
+               return NULL;
+       }
 
        for( iv=in,jv=refs; iv->bv_val != NULL ; iv++ ) {
                LDAPURLDesc *url;
@@ -294,7 +314,17 @@ BerVarray get_entry_referrals(
 
        if( i < 1 ) return NULL;
 
-       refs = ch_malloc( (i + 1) * sizeof(struct berval));
+       refs = SLAP_MALLOC( (i + 1) * sizeof(struct berval));
+       if( refs == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, CRIT, 
+                       "get_entry_referrals: SLAP_MALLOC failed\n", 0, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "get_entry_referrals: SLAP_MALLOC failed\n", 0, 0, 0 );
+#endif
+               return NULL;
+       }
 
        for( iv=attr->a_vals, jv=refs; iv->bv_val != NULL; iv++ ) {
                unsigned k;
index 53c0c5bfea1145fb450bf9f357b68095534c4668..da408fc394f549229b40b00d9f087a8a2857109b 100644 (file)
@@ -398,7 +398,17 @@ int slap_sasl_getdn( Connection *conn, char *id, int len,
 
                /* Build the new dn */
                c1 = dn->bv_val;
-               dn->bv_val = ch_malloc( len+1 );
+               dn->bv_val = SLAP_MALLOC( len+1 );
+               if( dn->bv_val == NULL ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG( TRANSPORT, ERR, 
+                               "slap_sasl_getdn: SLAP_MALLOC failed", 0, 0, 0 );
+#else
+                       Debug( LDAP_DEBUG_ANY, 
+                               "slap_sasl_getdn: SLAP_MALLOC failed", 0, 0, 0 );
+#endif
+                       return LDAP_OTHER;
+               }
                p = lutil_strcopy( dn->bv_val, "uid=" );
                p = lutil_strncopy( p, c1, dn->bv_len );
 
@@ -1209,10 +1219,20 @@ int slap_sasl_open( Connection *conn )
 
        session_callbacks =
 #if SASL_VERSION_MAJOR >= 2
-               ch_calloc( 5, sizeof(sasl_callback_t));
+               SLAP_CALLOC( 5, sizeof(sasl_callback_t));
 #else
-               ch_calloc( 3, sizeof(sasl_callback_t));
+               SLAP_CALLOC( 3, sizeof(sasl_callback_t));
 #endif
+       if( session_callbacks == NULL ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG( TRANSPORT, ERR, 
+                               "slap_sasl_open: SLAP_MALLOC failed", 0, 0, 0 );
+#else
+                       Debug( LDAP_DEBUG_ANY, 
+                               "slap_sasl_open: SLAP_MALLOC failed", 0, 0, 0 );
+#endif
+                       return -1;
+       }
        conn->c_sasl_extra = session_callbacks;
 
        session_callbacks[cb=0].id = SASL_CB_LOG;
index 5409bc1e002969ca07af2155b6e96591380517d1..e25d9a7abee867c90b9de07d8e6a19186adb36fc 100644 (file)
@@ -706,7 +706,7 @@ UTF8SubstringsassertionNormalize(
        SubstringsAssertion *nsa;
        int i;
 
-       nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
+       nsa = (SubstringsAssertion *)SLAP_CALLOC( 1, sizeof(SubstringsAssertion) );
        if( nsa == NULL ) {
                return NULL;
        }
@@ -723,7 +723,10 @@ UTF8SubstringsassertionNormalize(
                        /* empty */
                }
                nsa->sa_any = (struct berval *)
-                       ch_malloc( (i + 1) * sizeof(struct berval) );
+                       SLAP_MALLOC( (i + 1) * sizeof(struct berval) );
+               if( nsa->sa_any == NULL ) {
+                               goto err;
+               }
 
                for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
                        UTF8bvnormalize( &sa->sa_any[i], &nsa->sa_any[i], 
index 9d01b9c6717f7bd527531b9b4bc4c7fe8af210e7..2a839cbf34afb0f82bae669d1f5f52619638b7cd 100644 (file)
@@ -47,7 +47,7 @@ set_join (BerVarray lset, int op, BerVarray rset)
                if (lset == NULL || lset->bv_val == NULL) {
                        if (rset == NULL) {
                                if (lset == NULL)
-                                       return(ch_calloc(1, sizeof(struct berval)));
+                                       return(SLAP_CALLOC(1, sizeof(struct berval)));
                                return(lset);
                        }
                        slap_set_dispose(lset);
@@ -59,7 +59,7 @@ set_join (BerVarray lset, int op, BerVarray rset)
                }
 
                i = slap_set_size(lset) + slap_set_size(rset) + 1;
-               set = ch_calloc(i, sizeof(struct berval));
+               set = SLAP_CALLOC(i, sizeof(struct berval));
                if (set != NULL) {
                        /* set_chase() depends on this routine to
                         * keep the first elements of the result
@@ -87,7 +87,7 @@ set_join (BerVarray lset, int op, BerVarray rset)
 
        if (op == '&') {
                if (lset == NULL || lset->bv_val == NULL || rset == NULL || rset->bv_val == NULL) {
-                       set = ch_calloc(1, sizeof(struct berval));
+                       set = SLAP_CALLOC(1, sizeof(struct berval));
                } else {
                        set = lset;
                        lset = NULL;
@@ -126,7 +126,7 @@ set_chase (SLAP_SET_GATHER gatherer,
        bv.bv_val = attrstr;
 
        if (set == NULL)
-               return(ch_calloc(1, sizeof(struct berval)));
+               return(SLAP_CALLOC(1, sizeof(struct berval)));
 
        if (set->bv_val == NULL)
                return(set);
@@ -138,7 +138,7 @@ set_chase (SLAP_SET_GATHER gatherer,
        AC_MEMCPY(attrstr, attr->bv_val, attr->bv_len);
        attrstr[attr->bv_len] = 0;
 
-       nset = ch_calloc(1, sizeof(struct berval));
+       nset = SLAP_CALLOC(1, sizeof(struct berval));
        if (nset == NULL) {
                slap_set_dispose(set);
                return(NULL);
@@ -287,10 +287,10 @@ slap_set_filter (SLAP_SET_GATHER gatherer,
                        if (c == 0)
                                SF_ERROR(syntax);
                        
-                       set = ch_calloc(2, sizeof(struct berval));
+                       set = SLAP_CALLOC(2, sizeof(struct berval));
                        if (set == NULL)
                                SF_ERROR(memory);
-                       set->bv_val = ch_calloc(len + 1, sizeof(char));
+                       set->bv_val = SLAP_CALLOC(len + 1, sizeof(char));
                        if (set->bv_val == NULL)
                                SF_ERROR(memory);
                        AC_MEMCPY(set->bv_val, &filter[-len - 1], len);
@@ -331,7 +331,7 @@ slap_set_filter (SLAP_SET_GATHER gatherer,
                        {
                                if ((SF_TOP() == (void *)'/') || IS_SET(SF_TOP()))
                                        SF_ERROR(syntax);
-                               set = ch_calloc(2, sizeof(struct berval));
+                               set = SLAP_CALLOC(2, sizeof(struct berval));
                                if (set == NULL)
                                        SF_ERROR(memory);
                                ber_dupbv( set, this );
@@ -342,7 +342,7 @@ slap_set_filter (SLAP_SET_GATHER gatherer,
                        {
                                if ((SF_TOP() == (void *)'/') || IS_SET(SF_TOP()))
                                        SF_ERROR(syntax);
-                               set = ch_calloc(2, sizeof(struct berval));
+                               set = SLAP_CALLOC(2, sizeof(struct berval));
                                if (set == NULL)
                                        SF_ERROR(memory);
                                ber_dupbv( set, user );
index ff7cd450adfc7eea72d5e479af5fd74831697131..c7a38e9cc45d6c456b6f2b158fd52a60ead14f3b 100644 (file)
@@ -16,7 +16,9 @@
 #include "slap.h"
 #include <ldap_pvt.h>
 
+#if 0 /* unused */
 static char    *find_matching_paren( const char *s );
+#endif /* unused */
 static Filter  *str2list( const char *str, long unsigned int ftype);
 static Filter  *str2simple( const char *str);
 static int     str2subvals( const char *val, Filter *f);
index 9df3ab203769931793b849edf0de259e65cbe897..a232d066e98c4c9ae3346bb6fda8ae57bbd8741c 100644 (file)
@@ -324,6 +324,8 @@ value_match(
        struct berval nv1 = { 0, NULL };
        struct berval nv2 = { 0, NULL };
 
+       assert( mr != NULL );
+
        if( !mr->smr_match ) {
                return LDAP_INAPPROPRIATE_MATCHING;
        }