diff options
author | Anatol Belski <ab@php.net> | 2017-12-05 17:38:18 +0100 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2017-12-05 17:38:18 +0100 |
commit | 31b2b14a712f9a8e6beddec4522e12484259422b (patch) | |
tree | a7b9450fdb0d88f02ecc45dc3bcda5a35d49b72f | |
parent | 71a460ba7e9727af688e7284c87d5fa5397827c9 (diff) | |
download | php-git-31b2b14a712f9a8e6beddec4522e12484259422b.tar.gz |
Fixed bug #75601 Thread race in PCRE JIT support
-rw-r--r-- | ext/pcre/php_pcre.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index c0a6a848b6..42e577e351 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -67,6 +67,18 @@ PHPAPI ZEND_DECLARE_MODULE_GLOBALS(pcre) #define PCRE_JIT_STACK_MAX_SIZE (64 * 1024) ZEND_TLS pcre_jit_stack *jit_stack = NULL; #endif +#if defined(ZTS) && defined(HAVE_PCRE_JIT_SUPPORT) +static MUTEX_T pcre_mt = NULL; +#define php_pcre_mutex_alloc() if (!pcre_mt) pcre_mt = tsrm_mutex_alloc(); +#define php_pcre_mutex_free() if (pcre_mt) tsrm_mutex_free(pcre_mt); +#define php_pcre_mutex_lock() tsrm_mutex_lock(pcre_mt); +#define php_pcre_mutex_unlock() tsrm_mutex_unlock(pcre_mt); +#else +#define php_pcre_mutex_alloc() +#define php_pcre_mutex_free() +#define php_pcre_mutex_lock() +#define php_pcre_mutex_unlock() +#endif static void pcre_handle_exec_error(int pcre_code) /* {{{ */ { @@ -185,6 +197,8 @@ static PHP_MINIT_FUNCTION(pcre) { REGISTER_INI_ENTRIES(); + php_pcre_mutex_alloc(); + REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); @@ -211,6 +225,8 @@ static PHP_MSHUTDOWN_FUNCTION(pcre) { UNREGISTER_INI_ENTRIES(); + php_pcre_mutex_free(); + return SUCCESS; } /* }}} */ @@ -220,7 +236,9 @@ static PHP_MSHUTDOWN_FUNCTION(pcre) static PHP_RINIT_FUNCTION(pcre) { if (PCRE_G(jit) && jit_stack == NULL) { + php_pcre_mutex_lock(); jit_stack = pcre_jit_stack_alloc(PCRE_JIT_STACK_MIN_SIZE,PCRE_JIT_STACK_MAX_SIZE); + php_pcre_mutex_unlock(); } return SUCCESS; |