Skip to content

Commit 0943b79

Browse files
author
Andrei Zmievski
committed
MFH (pcre cache flush)
1 parent 6305213 commit 0943b79

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ext/pcre/php_pcre.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,21 @@ PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_
152152
back the compiled pattern, otherwise go on and compile it. */
153153
regex_len = strlen(regex);
154154
if (zend_hash_find(&PCRE_G(pcre_cache), regex, regex_len+1, (void **)&pce) == SUCCESS) {
155+
/*
156+
* We use a quick pcre_info() check to see whether cache is corrupted, and if it
157+
* is, we flush it and compile the pattern from scratch.
158+
*/
159+
if (pcre_info(pce->re, NULL, NULL) == PCRE_ERROR_BADMAGIC) {
160+
zend_hash_clean(&PCRE_G(pcre_cache));
161+
} else {
155162
#if HAVE_SETLOCALE
156-
if (!strcmp(pce->locale, locale)) {
163+
if (!strcmp(pce->locale, locale)) {
157164
#endif
158-
*extra = pce->extra;
159-
*preg_options = pce->preg_options;
160-
return pce->re;
165+
*extra = pce->extra;
166+
*preg_options = pce->preg_options;
167+
return pce->re;
161168
#if HAVE_SETLOCALE
169+
}
162170
}
163171
#endif
164172
}

0 commit comments

Comments
 (0)