Commit 2d98b19b authored by Julius Enarusai's avatar Julius Enarusai
Browse files

Converted ch_malloc, ch_calloc and ch_realloc calls to SLAP_MALLOC and
SLAP_CALLOC in add_value/add_value_one functions and propagated errors to
all functions that use these functions.
parent 24f1a11c
......@@ -602,7 +602,8 @@ at_schema_info( Entry *e )
return -1;
}
attr_merge( e, ad_attributeTypes, vals );
if( attr_merge( e, ad_attributeTypes, vals ) )
return -1;
ldap_memfree( vals[0].bv_val );
}
return 0;
......
......@@ -1591,7 +1591,8 @@ read_config( const char *fname, int depth )
vals[0].bv_val = cargv[1];
vals[0].bv_len = strlen( vals[0].bv_val );
value_add( &default_referral, vals );
if( value_add( &default_referral, vals ) )
return LDAP_OTHER;
#ifdef NEW_LOGGING
} else if ( strcasecmp( cargv[0], "logfile" ) == 0 ) {
......@@ -1975,7 +1976,8 @@ read_config( const char *fname, int depth )
vals[0].bv_val = cargv[1];
vals[0].bv_len = strlen( vals[0].bv_val );
value_add( &be->be_update_refs, vals );
if( value_add( &be->be_update_refs, vals ) )
return LDAP_OTHER;
/* replication log file to which changes are appended */
} else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
......
......@@ -409,7 +409,8 @@ cr_schema_info( Entry *e )
Debug( LDAP_DEBUG_TRACE, "Merging cr [%ld] %s\n",
(long) vals[0].bv_len, vals[0].bv_val, 0 );
#endif
attr_merge( e, ad_ditContentRules, vals );
if( attr_merge( e, ad_ditContentRules, vals ) )
return -1;
ldap_memfree( vals[0].bv_val );
}
#endif
......
......@@ -473,7 +473,8 @@ int mr_schema_info( Entry *e )
Debug( LDAP_DEBUG_TRACE, "Merging mr [%lu] %s\n",
mr->smr_str.bv_len, mr->smr_str.bv_val, 0 );
#endif
attr_merge_one( e, ad_matchingRules, &mr->smr_str );
if( attr_merge_one( e, ad_matchingRules, &mr->smr_str ) )
return -1;
}
return 0;
}
......@@ -500,7 +501,8 @@ int mru_schema_info( Entry *e )
Debug( LDAP_DEBUG_TRACE, "Merging mru [%lu] %s\n",
mru->smru_str.bv_len, mru->smru_str.bv_val, 0 );
#endif
attr_merge_one( e, ad_matchingRuleUse, &mru->smru_str );
if( attr_merge_one( e, ad_matchingRuleUse, &mru->smru_str ) )
return -1;
}
return 0;
}
......@@ -491,7 +491,8 @@ oc_schema_info( Entry *e )
Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s\n",
(long) vals[0].bv_len, vals[0].bv_val, 0 );
#endif
attr_merge( e, ad_objectClasses, vals );
if( attr_merge( e, ad_objectClasses, vals ) )
return -1;
ldap_memfree( vals[0].bv_val );
}
return 0;
......
......@@ -1267,7 +1267,8 @@ send_search_reference(
if( op->o_protocol < LDAP_VERSION3 ) {
/* save the references for the result */
if( refs[0].bv_val != NULL ) {
value_add( v2refs, refs );
if( value_add( v2refs, refs ) )
return LDAP_OTHER;
}
return 0;
}
......
......@@ -80,17 +80,21 @@ root_dse_info(
vals[0].bv_val = "top";
vals[0].bv_len = sizeof("top")-1;
attr_merge( e, ad_objectClass, vals );
if( attr_merge( e, ad_objectClass, vals ) )
return LDAP_OTHER;
vals[0].bv_val = "OpenLDAProotDSE";
vals[0].bv_len = sizeof("OpenLDAProotDSE")-1;
attr_merge( e, ad_objectClass, vals );
attr_merge( e, ad_structuralObjectClass, vals );
if( attr_merge( e, ad_objectClass, vals ) )
return LDAP_OTHER;
if( attr_merge( e, ad_structuralObjectClass, vals ) )
return LDAP_OTHER;
for ( i = 0; i < nbackends; i++ ) {
if ( backends[i].be_flags & SLAP_BFLAG_MONITOR ) {
vals[0] = backends[i].be_suffix[0];
attr_merge( e, ad_monitorContext, vals );
if( attr_merge( e, ad_monitorContext, vals ) )
return LDAP_OTHER;
continue;
}
if ( backends[i].be_flags & SLAP_BFLAG_GLUE_SUBORDINATE ) {
......@@ -98,7 +102,8 @@ root_dse_info(
}
for ( j = 0; backends[i].be_suffix[j].bv_val != NULL; j++ ) {
vals[0] = backends[i].be_suffix[j];
attr_merge( e, ad_namingContexts, vals );
if( attr_merge( e, ad_namingContexts, vals ) )
return LDAP_OTHER;
}
}
......@@ -107,17 +112,20 @@ root_dse_info(
/* supportedControl */
for ( i=0; (vals[0].bv_val = get_supported_ctrl(i)) != NULL; i++ ) {
vals[0].bv_len = strlen( vals[0].bv_val );
attr_merge( e, ad_supportedControl, vals );
if( attr_merge( e, ad_supportedControl, vals ) )
return LDAP_OTHER;
}
/* supportedExtension */
for ( i=0; (bv = get_supported_extop(i)) != NULL; i++ ) {
vals[0] = *bv;
attr_merge( e, ad_supportedExtension, vals );
if( attr_merge( e, ad_supportedExtension, vals ) )
return LDAP_OTHER;
}
/* supportedFeatures */
attr_merge( e, ad_supportedFeatures, supportedFeatures );
if( attr_merge( e, ad_supportedFeatures, supportedFeatures ) )
return LDAP_OTHER;
/* supportedLDAPVersion */
for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
......@@ -131,7 +139,8 @@ root_dse_info(
snprintf(buf, sizeof buf, "%d", i);
vals[0].bv_val = buf;
vals[0].bv_len = strlen( vals[0].bv_val );
attr_merge( e, ad_supportedLDAPVersion, vals );
if( attr_merge( e, ad_supportedLDAPVersion, vals ) )
return LDAP_OTHER;
}
/* supportedSASLMechanism */
......@@ -141,19 +150,22 @@ root_dse_info(
for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
vals[0].bv_val = supportedSASLMechanisms[i];
vals[0].bv_len = strlen( vals[0].bv_val );
attr_merge( e, ad_supportedSASLMechanisms, vals );
if( attr_merge( e, ad_supportedSASLMechanisms, vals ) )
return LDAP_OTHER;
}
ldap_charray_free( supportedSASLMechanisms );
}
if ( default_referral != NULL ) {
attr_merge( e, ad_ref, default_referral );
if( attr_merge( e, ad_ref, default_referral ) )
return LDAP_OTHER;
}
if( usr_attr != NULL) {
Attribute *a;
for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
attr_merge( e, a->a_desc, a->a_vals );
if( attr_merge( e, a->a_desc, a->a_vals ) )
return LDAP_OTHER;
}
}
......@@ -215,7 +227,8 @@ int read_root_dse_file( const char *fname )
*/
for(a = e->e_attrs; a != NULL; a = a->a_next) {
attr_merge( usr_attr, a->a_desc, a->a_vals );
if( attr_merge( usr_attr, a->a_desc, a->a_vals ) )
return LDAP_OTHER;
}
entry_free( e );
......
......@@ -33,7 +33,19 @@ schema_info( Entry **entry, const char **text )
Entry *e;
struct berval vals[5];
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
if( e == NULL ) {
/* Out of memory, do something about it */
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR,
"schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0,0 );
#else
Debug( LDAP_DEBUG_ANY,
"schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0, 0 );
#endif
*text = "out of memory";
return LDAP_OTHER;
}
e->e_attrs = NULL;
/* backend-specific schema info should be created by the
......@@ -45,7 +57,12 @@ schema_info( Entry **entry, const char **text )
vals[0].bv_val = "subentry";
vals[0].bv_len = sizeof("subentry")-1;
attr_merge_one( e, ad_structuralObjectClass, vals );
if( attr_merge_one( e, ad_structuralObjectClass, vals ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
return LDAP_OTHER;
}
vals[0].bv_val = "top";
vals[0].bv_len = sizeof("top")-1;
......@@ -56,7 +73,12 @@ schema_info( Entry **entry, const char **text )
vals[3].bv_val = "extensibleObject";
vals[3].bv_len = sizeof("extensibleObject")-1;
vals[4].bv_val = NULL;
attr_merge( e, ad_objectClass, vals );
if( attr_merge( e, ad_objectClass, vals ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
return LDAP_OTHER;
}
{
int rc;
......@@ -81,7 +103,12 @@ schema_info( Entry **entry, const char **text )
return LDAP_OTHER;
}
attr_merge_one( e, desc, vals );
if( attr_merge_one( e, desc, vals ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
return LDAP_OTHER;
}
}
{
......@@ -107,8 +134,18 @@ schema_info( Entry **entry, const char **text )
vals[0].bv_val = timebuf;
vals[0].bv_len = strlen( timebuf );
attr_merge_one( e, ad_createTimestamp, vals );
attr_merge_one( e, ad_modifyTimestamp, vals );
if( attr_merge_one( e, ad_createTimestamp, vals ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
return LDAP_OTHER;
}
if( attr_merge_one( e, ad_modifyTimestamp, vals ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
return LDAP_OTHER;
}
}
if ( syn_schema_info( e )
......
......@@ -222,7 +222,8 @@ syn_schema_info( Entry *e )
#endif
#endif
attr_merge( e, ad_ldapSyntaxes, vals );
if( attr_merge( e, ad_ldapSyntaxes, vals ) )
return -1;
ldap_memfree( vals[0].bv_val );
}
return 0;
......
......@@ -31,15 +31,35 @@ value_add(
; /* NULL */
if ( *vals == NULL ) {
*vals = (BerVarray) ch_malloc( (nn + 1)
*vals = (BerVarray) SLAP_MALLOC( (nn + 1)
* sizeof(struct berval) );
if( *vals == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR,
"value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
#else
Debug(LDAP_DEBUG_TRACE,
"value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
#endif
return LBER_ERROR_MEMORY;
}
n = 0;
} else {
for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
; /* Empty */
}
*vals = (BerVarray) ch_realloc( (char *) *vals,
*vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
(n + nn + 1) * sizeof(struct berval) );
if( *vals == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR,
"value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
#else
Debug(LDAP_DEBUG_TRACE,
"value_add: SLAP_MALLOC failed.\n", 0, 0, 0 );
#endif
return LBER_ERROR_MEMORY;
}
}
v2 = *vals + n;
......@@ -63,14 +83,34 @@ value_add_one(
BerVarray v2;
if ( *vals == NULL ) {
*vals = (BerVarray) ch_malloc( 2 * sizeof(struct berval) );
*vals = (BerVarray) SLAP_MALLOC( 2 * sizeof(struct berval) );
if( *vals == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR,
"value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
#else
Debug(LDAP_DEBUG_TRACE,
"value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
#endif
return LBER_ERROR_MEMORY;
}
n = 0;
} else {
for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
; /* Empty */
}
*vals = (BerVarray) ch_realloc( (char *) *vals,
*vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
(n + 2) * sizeof(struct berval) );
if( *vals == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR,
"value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
#else
Debug(LDAP_DEBUG_TRACE,
"value_add_one: SLAP_MALLOC failed.\n", 0, 0, 0 );
#endif
return LBER_ERROR_MEMORY;
}
}
v2 = *vals + n;
......
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