Skip to content

Commit ca66964

Browse files
author
foobar
committed
MFH: - Fixed bug #33200 (preg_replace(): magic_quotes_sybase=On makes 'e' modifier misbehave)
1 parent b73fec0 commit ca66964

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP 4 NEWS
77
them sort based on the current locale. (Derick)
88
- Changed sha1_file() and md5_file() functions to use streams instead of
99
low level IO. (Uwe)
10+
- Fixed bug #33200 (preg_replace(): magic_quotes_sybase=On makes 'e' modifier
11+
misbehave). (Jani)
1012
- Fixed bug #33072 (Add a safemode/open_basedir check for runtime save_path
1113
change) (Rasmus)
1214
- Fixed bug #33057 (Don't send extraneous entity-headers on a 304 as per

ext/pcre/php_pcre.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,9 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
750750
in instead of the backref */
751751
match = subject + offsets[backref<<1];
752752
match_len = offsets[(backref<<1)+1] - offsets[backref<<1];
753-
if (match_len)
754-
esc_match = php_addslashes(match, match_len, &esc_match_len, 0 TSRMLS_CC);
755-
else {
753+
if (match_len) {
754+
esc_match = php_addslashes_ex(match, match_len, &esc_match_len, 0, 1 TSRMLS_CC);
755+
} else {
756756
esc_match = match;
757757
esc_match_len = 0;
758758
}

ext/pcre/tests/bug33200.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #33200 (magic_quotes_sybase = On makes 'e' modifier misbehave)
3+
--INI--
4+
magic_quotes_sybase=1
5+
--FILE--
6+
<?php
7+
$str = 'some \'$sample\' text';
8+
$str = preg_replace("/(some.*text)/e", "strtoupper('\\1')", $str);
9+
echo $str;
10+
?>
11+
--EXPECT--
12+
SOME '$SAMPLE' TEXT

ext/standard/php_string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ PHPAPI char *php_strtoupper(char *s, size_t len);
116116
PHPAPI char *php_strtolower(char *s, size_t len);
117117
PHPAPI char *php_strtr(char *str, int len, char *str_from, char *str_to, int trlen);
118118
PHPAPI char *php_addslashes(char *str, int length, int *new_length, int freeit TSRMLS_DC);
119+
PHPAPI char *php_addslashes_ex(char *str, int length, int *new_length, int freeit, int ignore_sybase TSRMLS_DC);
119120
PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int freeit, char *what, int wlength TSRMLS_DC);
120121
PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC);
121122
PHPAPI void php_stripcslashes(char *str, int *len);

ext/standard/string.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,18 +2413,26 @@ PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int should_
24132413
}
24142414
/* }}} */
24152415

2416+
/* {{{ php_addslashes
2417+
*/
2418+
PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free TSRMLS_DC)
2419+
{
2420+
return php_addslashes_ex(str, length, new_length, should_free, 0 TSRMLS_CC);
2421+
}
2422+
/* }}} */
2423+
24162424
/* true static */
24172425
const unsigned char php_esc_list[256] = {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
24182426

2419-
/* {{{ php_addslashes
2427+
/* {{{ php_addslashes_ex
24202428
*/
2421-
PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free TSRMLS_DC)
2429+
PHPAPI char *php_addslashes_ex(char *str, int length, int *new_length, int should_free, int ignore_sybase TSRMLS_DC)
24222430
{
24232431
char *e = str + (length ? length : (length = strlen(str)));
24242432
char *p = str;
24252433
char *new_str, *ps;
24262434
int local_new_length = length;
2427-
int type = PG(magic_quotes_sybase) ? 1 : 0;
2435+
int type = (!ignore_sybase && PG(magic_quotes_sybase)) ? 1 : 0;
24282436

24292437
if (!new_length) {
24302438
new_length = &local_new_length;

0 commit comments

Comments
 (0)