From e75fbc953fe6243e9ab2061e5dd7a215cbe0b4e2 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 16 Jul 2015 18:58:23 +0100 Subject: [PATCH] ITS#8201 LDAPSTACKGUARD feature --- libraries/libldap/init.c | 10 ++++++++++ libraries/libldap/ldap-int.h | 1 + libraries/libldap_r/thr_posix.c | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index 68ff401d3f..9b9f6177bd 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -596,6 +596,10 @@ void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl char * ldap_int_hostname = NULL; #endif +#ifdef LDAP_R_COMPILE +int ldap_int_stackguard; +#endif + void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl ) { if ( gopts->ldo_valid == LDAP_INITIALIZED ) { @@ -664,6 +668,12 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl ) return; } +#ifdef LDAP_R_COMPILE + if( getenv("LDAPSTACKGUARD") != NULL ) { + ldap_int_stackguard = 1; + } +#endif + #ifdef HAVE_CYRUS_SASL { /* set authentication identity to current user name */ diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index fbcf93965c..5482572539 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -495,6 +495,7 @@ struct ldap { #ifdef LDAP_R_COMPILE LDAP_V ( ldap_pvt_thread_mutex_t ) ldap_int_resolv_mutex; LDAP_V ( ldap_pvt_thread_mutex_t ) ldap_int_hostname_mutex; +LDAP_V ( int ) ldap_int_stackguard; #ifdef HAVE_GSSAPI LDAP_V( ldap_pvt_thread_mutex_t ) ldap_int_gssapi_mutex; diff --git a/libraries/libldap_r/thr_posix.c b/libraries/libldap_r/thr_posix.c index ec6677f8c7..ce6cb206c5 100644 --- a/libraries/libldap_r/thr_posix.c +++ b/libraries/libldap_r/thr_posix.c @@ -33,6 +33,8 @@ #include "ldap_thr_debug.h" /* May rename the symbols defined below */ #include /* For pthread_kill() */ +extern int ldap_int_stackguard; + #if HAVE_PTHREADS < 6 # define LDAP_INT_THREAD_ATTR_DEFAULT pthread_attr_default # define LDAP_INT_THREAD_CONDATTR_DEFAULT pthread_condattr_default @@ -148,6 +150,8 @@ ldap_pvt_thread_create( ldap_pvt_thread_t * thread, #ifdef LDAP_PVT_THREAD_SET_STACK_SIZE /* this should be tunable */ pthread_attr_setstacksize( &attr, LDAP_PVT_THREAD_STACK_SIZE ); + if ( ldap_int_stackguard ) + pthread_attr_setguardsize( &attr, LDAP_PVT_THREAD_STACK_SIZE ); #endif #if HAVE_PTHREADS > 5 -- 2.39.5