andrei Thu May 26 17:48:35 2005 EDT
Modified files:
/php-src/ext/standard reg.c
Log:
Do a cache flush if we detect possible cache corruption (same as for
PCRE).
http://cvs.php.net/diff.php/php-src/ext/standard/reg.c?r1=1.79&r2=1.80&ty=u
Index: php-src/ext/standard/reg.c
diff -u php-src/ext/standard/reg.c:1.79 php-src/ext/standard/reg.c:1.80
--- php-src/ext/standard/reg.c:1.79 Mon Jul 19 03:19:45 2004
+++ php-src/ext/standard/reg.c Thu May 26 17:48:35 2005
@@ -17,7 +17,7 @@
| Jaakko Hyv�tti <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: reg.c,v 1.79 2004/07/19 07:19:45 andi Exp $ */
+/* $Id: reg.c,v 1.80 2005/05/26 21:48:35 andrei Exp $ */
#include <stdio.h>
#include <ctype.h>
@@ -33,6 +33,8 @@
int cflags;
} reg_cache;
+static int reg_magic = 0;
+
/* {{{ _php_regcomp
*/
static int _php_regcomp(regex_t *preg, const char *pattern, int cflags)
@@ -42,19 +44,34 @@
reg_cache *rc = NULL;
TSRMLS_FETCH();
- if(zend_hash_find(®(ht_rc), (char *) pattern, patlen+1, (void **)
&rc) == FAILURE ||
- rc->cflags != cflags) {
- r = regcomp(preg, pattern, cflags);
- if(!r) {
- reg_cache rcp;
-
- rcp.cflags = cflags;
- memcpy(&rcp.preg, preg, sizeof(*preg));
- zend_hash_update(®(ht_rc), (char *) pattern,
patlen+1,
- (void *) &rcp, sizeof(rcp), NULL);
+ if(zend_hash_find(®(ht_rc), (char *) pattern, patlen+1, (void **)
&rc) == SUCCESS
+ && rc->cflags == cflags) {
+ /*
+ * We use a saved magic number to see whether cache is
corrupted, and if it
+ * is, we flush it and compile the pattern from scratch.
+ */
+ if (rc->preg.re_magic != reg_magic) {
+ zend_hash_clean(®(ht_rc));
+ } else {
+ memcpy(preg, &rc->preg, sizeof(*preg));
+ return r;
}
- } else {
- memcpy(preg, &rc->preg, sizeof(*preg));
+ }
+
+ r = regcomp(preg, pattern, cflags);
+ if(!r) {
+ reg_cache rcp;
+
+ rcp.cflags = cflags;
+ memcpy(&rcp.preg, preg, sizeof(*preg));
+ /*
+ * Since we don't have access to the actual MAGIC1 definition
in the private
+ * header file, we save the magic value immediately after
compilation. Hopefully,
+ * it's good.
+ */
+ if (!reg_magic) reg_magic = preg->re_magic;
+ zend_hash_update(®(ht_rc), (char *) pattern, patlen+1,
+ (void *) &rcp, sizeof(rcp),
NULL);
}
return r;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php