From 2d98b19bf76b0ac01abf5df0dc2d05ae3c01e967 Mon Sep 17 00:00:00 2001 From: Julius Enarusai Date: Fri, 1 Nov 2002 18:59:52 +0000 Subject: [PATCH] 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. --- servers/slapd/at.c | 3 ++- servers/slapd/config.c | 6 +++-- servers/slapd/cr.c | 3 ++- servers/slapd/mr.c | 6 +++-- servers/slapd/oc.c | 3 ++- servers/slapd/result.c | 3 ++- servers/slapd/root_dse.c | 39 +++++++++++++++++++++----------- servers/slapd/schema.c | 49 +++++++++++++++++++++++++++++++++++----- servers/slapd/syntax.c | 3 ++- servers/slapd/value.c | 48 +++++++++++++++++++++++++++++++++++---- 10 files changed, 131 insertions(+), 32 deletions(-) diff --git a/servers/slapd/at.c b/servers/slapd/at.c index 7a6af1f79a..27facafff5 100644 --- a/servers/slapd/at.c +++ b/servers/slapd/at.c @@ -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; diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 55d6191939..37d3f2d1cc 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -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 ) { diff --git a/servers/slapd/cr.c b/servers/slapd/cr.c index f8f5216cb4..cef1279c43 100644 --- a/servers/slapd/cr.c +++ b/servers/slapd/cr.c @@ -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 diff --git a/servers/slapd/mr.c b/servers/slapd/mr.c index 069b72b370..64d02b3058 100644 --- a/servers/slapd/mr.c +++ b/servers/slapd/mr.c @@ -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; } diff --git a/servers/slapd/oc.c b/servers/slapd/oc.c index ff6a818303..4ce2b8b66a 100644 --- a/servers/slapd/oc.c +++ b/servers/slapd/oc.c @@ -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; diff --git a/servers/slapd/result.c b/servers/slapd/result.c index a7607d646b..e6f727b5e6 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -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; } diff --git a/servers/slapd/root_dse.c b/servers/slapd/root_dse.c index 854bb0e2ec..6225622ab1 100644 --- a/servers/slapd/root_dse.c +++ b/servers/slapd/root_dse.c @@ -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 ); diff --git a/servers/slapd/schema.c b/servers/slapd/schema.c index c9d4436e8b..4d401f8518 100644 --- a/servers/slapd/schema.c +++ b/servers/slapd/schema.c @@ -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 ) diff --git a/servers/slapd/syntax.c b/servers/slapd/syntax.c index 2c1bc91f6d..dbdd14618d 100644 --- a/servers/slapd/syntax.c +++ b/servers/slapd/syntax.c @@ -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; diff --git a/servers/slapd/value.c b/servers/slapd/value.c index b1288d0736..9df3ab2037 100644 --- a/servers/slapd/value.c +++ b/servers/slapd/value.c @@ -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; -- 2.39.5