]> granicus.if.org Git - php/commitdiff
MFH: - Fixed bug #33200 (preg_replace(): magic_quotes_sybase=On makes 'e' modifier...
authorfoobar <sniper@php.net>
Tue, 31 May 2005 12:55:33 +0000 (12:55 +0000)
committerfoobar <sniper@php.net>
Tue, 31 May 2005 12:55:33 +0000 (12:55 +0000)
NEWS
ext/pcre/php_pcre.c
ext/pcre/tests/bug33200.phpt [new file with mode: 0644]
ext/standard/php_string.h
ext/standard/string.c

diff --git a/NEWS b/NEWS
index 2ade2bc147c07886759500691c1e588de195debf..81c234e0695f4593a3ef05175deeb6ce3c82f79a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ PHP                                                                        NEWS
 - Fixed ext/mysqli to allocate less memory when fetching bound params
   of type (MEDIUM|LONG)BLOB/(MEDIUM|LONG)TEXT. (Andrey)
 - Fixed memory corruption in ImageTTFText() with 64bit systems. (Andrey)
+- Fixed bug #33200 (preg_replace(): magic_quotes_sybase=On makes 'e' modifier
+  misbehave). (Jani)
 - Fixed bug #33185 (--enable-session=shared does not build). (Jani)
 - Fixed bug #33164 (Soap extension incorrectly detects HTTP/1.1). (Ilia)
 - Fixed bug #33116 (crash when assigning class name to global variable in
index bde3fe09ff820146fcce1ba523aed4af7920a8f5..64a1511a8d7b2d8ead9f6acf6090dc02ffce0ff4 100644 (file)
@@ -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 (file)
index 0000000..b00b72a
--- /dev/null
@@ -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
index 9eddc44055441c9fc83b4d59baf0a031b1d78136..327bda0e2d0fe70992aa95771fcc83e3f9f33a20 100644 (file)
@@ -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);
index 7926932706e231ce77bf86876888cff0dc6e9791..e44ca6225cf304e8f88079b5d988cb5bad00f7a4 100644 (file)
@@ -2861,6 +2861,14 @@ PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int should_
 /* {{{ php_addslashes
  */
 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;
@@ -2880,7 +2888,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':