summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Zmievski <andrei@php.net>2005-05-26 21:49:04 +0000
committerAndrei Zmievski <andrei@php.net>2005-05-26 21:49:04 +0000
commit7cb6bc0d50eeee4dab27a03e93366e58f2413e7a (patch)
tree43b4dc81c106b2b7bc08dc5da4e87fae796ebaee
parentb57e6a484ab29a476b4e0d19138e518483dbe2c9 (diff)
downloadphp-git-7cb6bc0d50eeee4dab27a03e93366e58f2413e7a.tar.gz
MFH
-rw-r--r--ext/ereg/ereg.c41
-rw-r--r--ext/standard/reg.c41
2 files changed, 58 insertions, 24 deletions
diff --git a/ext/ereg/ereg.c b/ext/ereg/ereg.c
index 193e43a247..ed07324599 100644
--- a/ext/ereg/ereg.c
+++ b/ext/ereg/ereg.c
@@ -33,6 +33,8 @@ typedef struct {
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 @@ static int _php_regcomp(regex_t *preg, const char *pattern, int cflags)
reg_cache *rc = NULL;
TSRMLS_FETCH();
- if(zend_hash_find(&REG(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(&REG(ht_rc), (char *) pattern, patlen+1,
- (void *) &rcp, sizeof(rcp), NULL);
+ if(zend_hash_find(&REG(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(&REG(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(&REG(ht_rc), (char *) pattern, patlen+1,
+ (void *) &rcp, sizeof(rcp), NULL);
}
return r;
diff --git a/ext/standard/reg.c b/ext/standard/reg.c
index 193e43a247..ed07324599 100644
--- a/ext/standard/reg.c
+++ b/ext/standard/reg.c
@@ -33,6 +33,8 @@ typedef struct {
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 @@ static int _php_regcomp(regex_t *preg, const char *pattern, int cflags)
reg_cache *rc = NULL;
TSRMLS_FETCH();
- if(zend_hash_find(&REG(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(&REG(ht_rc), (char *) pattern, patlen+1,
- (void *) &rcp, sizeof(rcp), NULL);
+ if(zend_hash_find(&REG(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(&REG(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(&REG(ht_rc), (char *) pattern, patlen+1,
+ (void *) &rcp, sizeof(rcp), NULL);
}
return r;