Skip to content

Commit 0716ddc

Browse files
committed
Merge branch 'PHP-5.4'
* PHP-5.4: Fixed bug #63180 (Corruption of hash tables) fix bug #63369 Conflicts: NEWS
2 parents 01dee2c + 68b229e commit 0716ddc

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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)