com php-src: Fixed bug #75601 Thread race in PCRE JIT support: ext/pcre/php_pcre.c
| From: | Anatol Belski | Date: | Tue, 05 Dec 2017 16:40:00 +0000 |
| Subject: | com php-src: Fixed bug #75601 Thread race in PCRE JIT support: ext/pcre/php_pcre.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100501@lists.php.net to get a copy of this message | ||
Commit: 75a2ee7f7bad4d3bc7bc60c181eabcc6d58c7937
Author: Anatol Belski <ab@php.net> Tue, 5 Dec 2017 17:40:00 +0100
Parents: ed2434a6aa68d3fe01fc6213f3c1a386dbe2a558
Branches: PHP-7.2 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=75a2ee7f7bad4d3bc7bc60c181eabcc6d58c7937
Log:
Fixed bug #75601 Thread race in PCRE JIT support
Bugs:
https://bugs.php.net/75601
Changed paths:
M ext/pcre/php_pcre.c
Diff:
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index aa2695e..64db5da 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -68,6 +68,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 (tsrm_is_main_thread() && !pcre_mt) pcre_mt =
tsrm_mutex_alloc();
+#define php_pcre_mutex_free() if (tsrm_is_main_thread() && 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) /* {{{ */
{
@@ -190,6 +202,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);
@@ -217,6 +231,8 @@ static PHP_MSHUTDOWN_FUNCTION(pcre)
{
UNREGISTER_INI_ENTRIES();
+ php_pcre_mutex_free();
+
return SUCCESS;
}
/* }}} */
@@ -226,7 +242,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;