]> git.sur5r.net Git - openldap/commitdiff
Converted ch_malloc, ch_calloc and ch_realloc calls to SLAP_MALLOC and
authorJulius Enarusai <julius@openldap.org>
Fri, 1 Nov 2002 18:59:52 +0000 (18:59 +0000)
committerJulius Enarusai <julius@openldap.org>
Fri, 1 Nov 2002 18:59:52 +0000 (18:59 +0000)
SLAP_CALLOC in add_value/add_value_one functions and propagated errors to
all functions that use these functions.

servers/slapd/at.c
servers/slapd/config.c
servers/slapd/cr.c
servers/slapd/mr.c
servers/slapd/oc.c
servers/slapd/result.c
servers/slapd/root_dse.c
servers/slapd/schema.c
servers/slapd/syntax.c
servers/slapd/value.c

index 7a6af1f79ae0a05e3eec906679c6e9fa064cdac6..27facafff50b885212e29f62ec22abf0c11f39a5 100644 (file)
@@ -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;
index 55d6191939be03576d7848217abe3ea79a4354a0..37d3f2d1cc116c76d6bf3d327691b068d0359a14 100644 (file)
@@ -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 ) {
index f8f5216cb404956f2c4ede68afbb12c9342bac33..cef1279c435f15ddb6b9af439ecd188c741a2a12 100644 (file)
@@ -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
index 069b72b370f685df24595810b1df211e6440d566..64d02b30581fd51d806e7289d3eaceafc7c67aae 100644 (file)
@@ -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;
 }
index ff6a81830344bcc302d320d8a37f87a2e846a67b..4ce2b8b66abf4a76aefe072a2a3da248a9e0928f 100644 (file)
@@ -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;
index a7607d646b3b43fa91981bda5d1b1ba86f1c242f..e6f727b5e68a8c6d16081d1d178a96dcc8a2faf5 100644 (file)
@@ -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;
        }
index 854bb0e2ec9e7652288cae77f13244da46c4c083..6225622ab148638f612ab366c079f93332cee7a8 100644 (file)
@@ -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 );
index c9d4436e8bc12f7da86f7cb4b8b8801cc9d2523e..4d401f85186e1b2833dffa6eedfe0bab03a460df 100644 (file)
@@ -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 ) 
index 2c1bc91f6d07ac334e206f21ead440c29ac557da..dbdd14618dbf843568effd673475264a90930f57 100644 (file)
@@ -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;
index b1288d07369ce3e7b24aaf0afc99196d40379cd0..9df3ab203769931793b849edf0de259e65cbe897 100644 (file)
@@ -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;