From 388c076768268db67ae808099da49ee2e07c2c41 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 13 Aug 2005 18:43:20 +0000 Subject: [PATCH] fix ITS#3932 - regex/rewrite concurrency issue --- libraries/librewrite/rewrite-int.h | 3 +++ libraries/librewrite/rule.c | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libraries/librewrite/rewrite-int.h b/libraries/librewrite/rewrite-int.h index ac616e16d0..4b5a60bee2 100644 --- a/libraries/librewrite/rewrite-int.h +++ b/libraries/librewrite/rewrite-int.h @@ -206,6 +206,9 @@ struct rewrite_rule { char *lr_pattern; char *lr_subststring; char *lr_flagstring; +#ifdef USE_REWRITE_LDAP_PVT_THREADS + ldap_pvt_thread_mutex_t lr_mutex; +#endif /* USE_REWRITE_LDAP_PVT_THREADS */ regex_t lr_regex; /* diff --git a/libraries/librewrite/rule.c b/libraries/librewrite/rule.c index b3fba216e9..9be1d844cb 100644 --- a/libraries/librewrite/rule.c +++ b/libraries/librewrite/rule.c @@ -346,6 +346,14 @@ rewrite_rule_compile( return REWRITE_ERR; } +#ifdef USE_REWRITE_LDAP_PVT_THREADS + if ( ldap_pvt_thread_mutex_init( &rule->lr_mutex ) ) { + regfree( &rule->lr_regex ); + free( rule ); + return REWRITE_ERR; + } +#endif /* USE_REWRITE_LDAP_PVT_THREADS */ + /* * Just to remember them ... */ @@ -418,7 +426,15 @@ recurse:; rule->lr_pattern, string, strcnt + 1 ); op->lo_num_passes++; - if ( regexec( &rule->lr_regex, string, nmatch, match, 0 ) != 0 ) { + +#ifdef USE_REWRITE_LDAP_PVT_THREADS + ldap_pvt_thread_mutex_lock( &rule->lr_mutex ); +#endif /* USE_REWRITE_LDAP_PVT_THREADS */ + rc = regexec( &rule->lr_regex, string, nmatch, match, 0 ); +#ifdef USE_REWRITE_LDAP_PVT_THREADS + ldap_pvt_thread_mutex_unlock( &rule->lr_mutex ); +#endif /* USE_REWRITE_LDAP_PVT_THREADS */ + if ( rc != 0 ) { if ( *result == NULL && string != arg ) { free( string ); } @@ -487,6 +503,9 @@ rewrite_rule_destroy( } regfree( &rule->lr_regex ); +#ifdef USE_REWRITE_LDAP_PVT_THREADS + ldap_pvt_thread_mutex_destroy( &rule->lr_mutex ); +#endif /* USE_REWRITE_LDAP_PVT_THREADS */ for ( action = rule->lr_action; action; ) { struct rewrite_action *curraction = action; -- 2.39.5