From: Andrei Zmievski Date: Tue, 24 May 2005 21:07:32 +0000 (+0000) Subject: Flush regexp cache if we detect corruption. X-Git-Tag: php-5.0.1b1~172 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=79742f81a2a7db076519a3d1fa1068d3a64276ea;p=php Flush regexp cache if we detect corruption. --- diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index da7f15427a..5e404b0ddf 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -161,14 +161,22 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr back the compiled pattern, otherwise go on and compile it. */ regex_len = strlen(regex); if (zend_hash_find(&PCRE_G(pcre_cache), regex, regex_len+1, (void **)&pce) == SUCCESS) { + /* + * We use a quick pcre_info() check to see whether cache is corrupted, and if it + * is, we flush it and compile the pattern from scratch. + */ + if (pcre_info(pce->re, NULL, NULL) == PCRE_ERROR_BADMAGIC) { + zend_hash_clean(&PCRE_G(pcre_cache)); + } else { #if HAVE_SETLOCALE - if (!strcmp(pce->locale, locale)) { + if (!strcmp(pce->locale, locale)) { #endif - *extra = pce->extra; - *preg_options = pce->preg_options; - *compile_options = pce->compile_options; - return pce->re; + *extra = pce->extra; + *preg_options = pce->preg_options; + *compile_options = pce->compile_options; + return pce->re; #if HAVE_SETLOCALE + } } #endif }