From: Howard Chu Date: Wed, 3 Jul 2019 15:59:53 +0000 (+0100) Subject: ITS#8977 don't use any stack allocated IDLs X-Git-Tag: OPENLDAP_REL_ENG_2_5_0ALPHA~67^2~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfe9152c4c4e6e9ae2959805b09e149036a3f03d;p=thirdparty%2Fopenldap.git ITS#8977 don't use any stack allocated IDLs --- diff --git a/servers/slapd/back-mdb/search.c b/servers/slapd/back-mdb/search.c index 153c2d3916..796e24493b 100644 --- a/servers/slapd/back-mdb/search.c +++ b/servers/slapd/back-mdb/search.c @@ -416,8 +416,7 @@ mdb_search( Operation *op, SlapReply *rs ) struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private; ID id, cursor, nsubs, ncand, cscope; ID lastid = NOID; - ID candidates[MDB_idl_um_size]; - ID iscopes[MDB_idl_db_size]; + ID *candidates, *iscopes; ID2 *scopes; void *stack; Entry *e = NULL, *base = NULL; @@ -465,7 +464,9 @@ mdb_search( Operation *op, SlapReply *rs ) } scopes = scope_chunk_get( op ); - stack = search_stack( op ); + candidates = search_stack( op ); + iscopes = candidates + MDB_idl_um_size; + stack = iscopes + MDB_idl_db_size; isc.mt = ltid; isc.mc = mcd; isc.scopes = scopes; @@ -1268,6 +1269,11 @@ static int oc_filter( return rc; } +typedef struct IDLchunk { + unsigned int logn; + unsigned int pad; +} IDLchunk; + static void search_stack_free( void *key, void *data ) { ber_memfree_x(data, NULL); @@ -1276,26 +1282,31 @@ static void search_stack_free( void *key, void *data ) static void *search_stack( Operation *op ) { struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private; - void *ret = NULL; + IDLchunk *ic = NULL; if ( op->o_threadctx ) { ldap_pvt_thread_pool_getkey( op->o_threadctx, (void *)search_stack, - &ret, NULL ); + &ic, NULL ); } else { - ret = mdb->mi_search_stack; + ic = mdb->mi_search_stack; } - if ( !ret ) { - ret = ch_malloc( mdb->mi_search_stack_depth * MDB_idl_um_size - * sizeof( ID ) ); + if ( ic && ic->logn != MDB_idl_logn ) { + ber_memfree_x( ic, NULL ); + ic = NULL; + } + + if ( !ic ) { + ic = ch_malloc(( mdb->mi_search_stack_depth + 2 ) * MDB_idl_um_size + * sizeof( ID ) + sizeof( IDLchunk ) ); if ( op->o_threadctx ) { ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)search_stack, - ret, search_stack_free, NULL, NULL ); + ic, search_stack_free, NULL, NULL ); } else { - mdb->mi_search_stack = ret; + mdb->mi_search_stack = ic; } } - return ret; + return ic+1; } static int search_candidates(