Skip to content

Commit 68b229e

Browse files
committed
Fixed bug #63180 (Corruption of hash tables)
1 parent f2bffdc commit 68b229e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PHP NEWS
2020
(Chris Jones)
2121

2222
- PCRE:
23+
. Fixed bug #63180 (Corruption of hash tables). (Dmitry)
2324
. Fixed bug #63055 (Segfault in zend_gc with SF2 testsuite).
2425
(Dmitry, Laruence)
2526
. Fixed bug #63284 (Upgrade PCRE to 8.31). (Anatoliy)

ext/pcre/php_pcre.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le
248248
#endif
249249
pcre_cache_entry *pce;
250250
pcre_cache_entry new_entry;
251+
char *tmp = NULL;
251252

252253
/* Try to lookup the cached regex entry, and if successful, just pass
253254
back the compiled pattern, otherwise go on and compile it. */
@@ -438,9 +439,26 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le
438439
new_entry.locale = pestrdup(locale, 1);
439440
new_entry.tables = tables;
440441
#endif
442+
443+
/*
444+
* Interned strings are not duplicated when stored in HashTable,
445+
* but all the interned strings created during HTTP request are removed
446+
* at end of request. However PCRE_G(pcre_cache) must be consistent
447+
* on the next request as well. So we disable usage of interned strings
448+
* as hash keys especually for this table.
449+
* See bug #63180
450+
*/
451+
if (IS_INTERNED(regex)) {
452+
regex = tmp = estrndup(regex, regex_len);
453+
}
454+
441455
zend_hash_update(&PCRE_G(pcre_cache), regex, regex_len+1, (void *)&new_entry,
442456
sizeof(pcre_cache_entry), (void**)&pce);
443457

458+
if (tmp) {
459+
efree(tmp);
460+
}
461+
444462
return pce;
445463
}
446464
/* }}} */

0 commit comments

Comments
 (0)