Skip to content

Commit 1b29dc0

Browse files
committed
Fix yet one data race in PCRE
PCRE 8.x initializes the pattern compiler on demand during the first pcre_study call. It could be worse, but since the compiled patterns are cached, the locking impact is minimal. PCRE 10.x always compiles the pattern and thread sanitizer doesn't complain about the compiler initialization, thus the newer PCRE version seems to be unafected.
1 parent 092fd44 commit 1b29dc0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎ext/pcre/php_pcre.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ PHPAPI ZEND_DECLARE_MODULE_GLOBALS(pcre)
6767
#define PCRE_JIT_STACK_MAX_SIZE (64 * 1024)
6868
ZEND_TLS pcre_jit_stack *jit_stack = NULL;
6969
#endif
70-
#if defined(ZTS) && defined(HAVE_PCRE_JIT_SUPPORT)
70+
#if defined(ZTS)
7171
static MUTEX_T pcre_mt = NULL;
7272
#define php_pcre_mutex_alloc() if (!pcre_mt) pcre_mt = tsrm_mutex_alloc();
7373
#define php_pcre_mutex_free() if (pcre_mt) tsrm_mutex_free(pcre_mt); pcre_mt = NULL;
@@ -538,7 +538,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
538538
/* If study option was specified, study the pattern and
539539
store the result in extra for passing to pcre_exec. */
540540
if (do_study) {
541+
php_pcre_mutex_lock();
541542
extra = pcre_study(re, soptions, &error);
543+
php_pcre_mutex_unlock();
542544
if (extra) {
543545
extra->flags |= PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION;
544546
extra->match_limit = (unsigned long)PCRE_G(backtrack_limit);

0 commit comments

Comments
 (0)