summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfoobar <sniper@php.net>2005-05-31 12:54:56 +0000
committerfoobar <sniper@php.net>2005-05-31 12:54:56 +0000
commit156a9089977828e75b9dc7b06658079a0ff20695 (patch)
tree7cfa68f093eefdeca563d05953208531ef2cf045
parent747074f9888b5062feb3e0fa427d98fb67e657ce (diff)
downloadphp-git-156a9089977828e75b9dc7b06658079a0ff20695.tar.gz
- Fixed bug #33200 (preg_replace(): magic_quotes_sybase=On makes 'e' modifier misbehave)
-rw-r--r--ext/pcre/php_pcre.c6
-rw-r--r--ext/pcre/tests/bug33200.phpt12
-rw-r--r--ext/standard/php_string.h1
-rw-r--r--ext/standard/string.c10
4 files changed, 25 insertions, 4 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 5e404b0ddf..cf518b4506 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -761,9 +761,9 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
in instead of the backref */
match = subject + offsets[backref<<1];
match_len = offsets[(backref<<1)+1] - offsets[backref<<1];
- if (match_len)
- esc_match = php_addslashes(match, match_len, &esc_match_len, 0 TSRMLS_CC);
- else {
+ if (match_len) {
+ esc_match = php_addslashes_ex(match, match_len, &esc_match_len, 0, 1 TSRMLS_CC);
+ } else {
esc_match = match;
esc_match_len = 0;
}
diff --git a/ext/pcre/tests/bug33200.phpt b/ext/pcre/tests/bug33200.phpt
new file mode 100644
index 0000000000..b00b72ac28
--- /dev/null
+++ b/ext/pcre/tests/bug33200.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Bug #33200 (magic_quotes_sybase = On makes 'e' modifier misbehave)
+--INI--
+magic_quotes_sybase=1
+--FILE--
+<?php
+$str = 'some \'$sample\' text';
+$str = preg_replace("/(some.*text)/e", "strtoupper('\\1')", $str);
+echo $str;
+?>
+--EXPECT--
+SOME '$SAMPLE' TEXT
diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h
index 9eddc44055..327bda0e2d 100644
--- a/ext/standard/php_string.h
+++ b/ext/standard/php_string.h
@@ -119,6 +119,7 @@ PHPAPI char *php_strtoupper(char *s, size_t len);
PHPAPI char *php_strtolower(char *s, size_t len);
PHPAPI char *php_strtr(char *str, int len, char *str_from, char *str_to, int trlen);
PHPAPI char *php_addslashes(char *str, int length, int *new_length, int freeit TSRMLS_DC);
+PHPAPI char *php_addslashes_ex(char *str, int length, int *new_length, int freeit, int ignore_sybase TSRMLS_DC);
PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int freeit, char *what, int wlength TSRMLS_DC);
PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC);
PHPAPI void php_stripcslashes(char *str, int *len);
diff --git a/ext/standard/string.c b/ext/standard/string.c
index e65930f04d..9b356babf8 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -2910,6 +2910,14 @@ PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int should_
*/
PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free TSRMLS_DC)
{
+ return php_addslashes_ex(str, length, new_length, should_free, 0 TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ php_addslashes_ex
+ */
+PHPAPI char *php_addslashes_ex(char *str, int length, int *new_length, int should_free, int ignore_sybase TSRMLS_DC)
+{
/* maximum string length, worst case situation */
char *new_str;
char *source, *target;
@@ -2928,7 +2936,7 @@ PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_f
end = source + length;
target = new_str;
- if (PG(magic_quotes_sybase)) {
+ if (!ignore_sybase && PG(magic_quotes_sybase)) {
while (source < end) {
switch (*source) {
case '\0':