Commit c2f87979 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

malloc fixes and other misc cleanup

parent 2062fc65
......@@ -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++ ) {
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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] );
......
......@@ -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;
......
......@@ -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;
......
......@@ -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],
......
......@@ -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 );
......
......@@ -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);
......
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment