php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #73483
Patch use-regex-cache-key-with-locale revision 2016-11-10 15:32 UTC by alex at buayacorp dot com

Patch use-regex-cache-key-with-locale for PCRE related Bug #73483

Patch version 2016-11-10 15:32 UTC

Return to Bug #73483 | Download this patch
Patch Revisions:

Developer: alex@buayacorp.com

--- clean/php-7.0.12/ext/pcre/php_pcre.c	2016-10-13 16:04:58.000000000 +0200
+++ php-7.0.12/ext/pcre/php_pcre.c	2016-11-10 16:10:21.523631221 +0100
@@ -320,10 +320,17 @@
 	pcre_cache_entry	*pce;
 	pcre_cache_entry	 new_entry;
 	int					 rc;
+	zend_string *regex_cache_key;
+
+	if (BG(locale_string)) {
+		regex_cache_key = strpprintf(0, "%s%s", ZSTR_VAL(regex), ZSTR_VAL(BG(locale_string)) );
+	} else {
+		regex_cache_key = regex;
+	}
 
 	/* Try to lookup the cached regex entry, and if successful, just pass
 	   back the compiled pattern, otherwise go on and compile it. */
-	pce = zend_hash_find_ptr(&PCRE_G(pcre_cache), regex);
+	pce = zend_hash_find_ptr(&PCRE_G(pcre_cache), regex_cache_key);
 	if (pce) {
 #if HAVE_SETLOCALE
 		if (pce->locale == BG(locale_string) ||
@@ -556,14 +563,14 @@
 	 * as hash keys especually for this table.
 	 * See bug #63180
 	 */
-	if (!ZSTR_IS_INTERNED(regex) || !(GC_FLAGS(regex) & IS_STR_PERMANENT)) {
-		zend_string *str = zend_string_init(ZSTR_VAL(regex), ZSTR_LEN(regex), 1);
+	if (!ZSTR_IS_INTERNED(regex_cache_key) || !(GC_FLAGS(regex_cache_key) & IS_STR_PERMANENT)) {
+		zend_string *str = zend_string_init(ZSTR_VAL(regex_cache_key), ZSTR_LEN(regex_cache_key), 1);
 		GC_REFCOUNT(str) = 0; /* will be incremented by zend_hash_update_mem() */
-		ZSTR_H(str) = ZSTR_H(regex);
+		ZSTR_H(str) = ZSTR_H(regex_cache_key);
 		regex = str;
 	}
 
-	pce = zend_hash_update_mem(&PCRE_G(pcre_cache), regex, &new_entry, sizeof(pcre_cache_entry));
+	pce = zend_hash_update_mem(&PCRE_G(pcre_cache), regex_cache_key, &new_entry, sizeof(pcre_cache_entry));
 
 	return pce;
 }
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC