Skip to content

Commit 2d2995f

Browse files
committed
Fixed bug #61043: Regression in magic_quotes_gpc fix (CVE-2012-0831)
Merge commit 'refs/pull/12/head' of git://github.com/php/php-src into 5.3 Signed-off-by: Gustavo André dos Santos Lopes <[email protected]>
2 parents 657547f + d1fd543 commit 2d2995f

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ PHP NEWS
1414
(Nikic, Laruence)
1515
. Fixed bug #61058 (array_fill leaks if start index is PHP_INT_MAX).
1616
(Laruence)
17+
. Fixed bug #61043 (Regression in magic_quotes_gpc fix for CVE-2012-0831).
18+
(Ondřej Surý)
1719
. Fixed bug #61000 (Exceeding max nesting level doesn't delete numerical
1820
vars). (Laruence)
1921
. Fix bug #60895 (Possible invalid handler usage in windows random

main/php_variables.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ void _php_import_environment_variables(zval *array_ptr TSRMLS_DC)
450450
/* turn off magic_quotes while importing environment variables */
451451
int magic_quotes_gpc = PG(magic_quotes_gpc);
452452

453-
if (PG(magic_quotes_gpc)) {
453+
if (magic_quotes_gpc) {
454454
zend_alter_ini_entry_ex("magic_quotes_gpc", sizeof("magic_quotes_gpc"), "0", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_ACTIVATE, 1 TSRMLS_CC);
455455
}
456456

@@ -471,7 +471,10 @@ void _php_import_environment_variables(zval *array_ptr TSRMLS_DC)
471471
if (t != buf && t != NULL) {
472472
efree(t);
473473
}
474-
PG(magic_quotes_gpc) = magic_quotes_gpc;
474+
475+
if (magic_quotes_gpc) {
476+
zend_alter_ini_entry_ex("magic_quotes_gpc", sizeof("magic_quotes_gpc"), "1", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_ACTIVATE, 1 TSRMLS_CC);
477+
}
475478
}
476479

477480
zend_bool php_std_auto_global_callback(char *name, uint name_len TSRMLS_DC)
@@ -595,7 +598,7 @@ static inline void php_register_server_variables(TSRMLS_D)
595598
zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]);
596599
}
597600
PG(http_globals)[TRACK_VARS_SERVER] = array_ptr;
598-
if (PG(magic_quotes_gpc)) {
601+
if (magic_quotes_gpc) {
599602
zend_alter_ini_entry_ex("magic_quotes_gpc", sizeof("magic_quotes_gpc"), "0", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_ACTIVATE, 1 TSRMLS_CC);
600603
}
601604

@@ -622,7 +625,9 @@ static inline void php_register_server_variables(TSRMLS_D)
622625
php_register_variable_ex("REQUEST_TIME", &new_entry, array_ptr TSRMLS_CC);
623626
}
624627

625-
PG(magic_quotes_gpc) = magic_quotes_gpc;
628+
if (magic_quotes_gpc) {
629+
zend_alter_ini_entry_ex("magic_quotes_gpc", sizeof("magic_quotes_gpc"), "1", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_ACTIVATE, 1 TSRMLS_CC);
630+
}
626631
}
627632
/* }}} */
628633

sapi/cgi/cgi_main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
624624
int filter_arg = (array_ptr == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER;
625625

626626
/* turn off magic_quotes while importing environment variables */
627-
if (PG(magic_quotes_gpc)) {
627+
if (magic_quotes_gpc) {
628628
zend_alter_ini_entry_ex("magic_quotes_gpc", sizeof("magic_quotes_gpc"), "0", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_ACTIVATE, 1 TSRMLS_CC);
629629
}
630630
for (zend_hash_internal_pointer_reset_ex(request->env, &pos);
@@ -638,7 +638,9 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
638638
php_register_variable_safe(var, *val, new_val_len, array_ptr TSRMLS_CC);
639639
}
640640
}
641-
PG(magic_quotes_gpc) = magic_quotes_gpc;
641+
if (magic_quotes_gpc) {
642+
zend_alter_ini_entry_ex("magic_quotes_gpc", sizeof("magic_quotes_gpc"), "1", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_ACTIVATE, 1 TSRMLS_CC);
643+
}
642644
}
643645
}
644646

sapi/fpm/fpm/fpm_main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
595595
filter_arg = (array_ptr == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER;
596596

597597
/* turn off magic_quotes while importing environment variables */
598-
if (PG(magic_quotes_gpc)) {
598+
if (magic_quotes_gpc) {
599599
zend_alter_ini_entry_ex("magic_quotes_gpc", sizeof("magic_quotes_gpc"), "0", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_ACTIVATE, 1 TSRMLS_CC);
600600
}
601601
for (zend_hash_internal_pointer_reset_ex(request->env, &pos);
@@ -609,7 +609,9 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
609609
php_register_variable_safe(var, *val, new_val_len, array_ptr TSRMLS_CC);
610610
}
611611
}
612-
PG(magic_quotes_gpc) = magic_quotes_gpc;
612+
if (magic_quotes_gpc) {
613+
zend_alter_ini_entry_ex("magic_quotes_gpc", sizeof("magic_quotes_gpc"), "1", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_ACTIVATE, 1 TSRMLS_CC);
614+
}
613615
}
614616

615617
static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC)

tests/basic/magic_quotes_gpc.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Bug #61043 (Regression in magic_quotes_gpc fix for CVE-2012-0831)
3+
--INI--
4+
error_reporting=E_ALL & ~E_DEPRECATED
5+
magic_quotes_gpc=On
6+
--FILE--
7+
<?php
8+
var_dump(ini_get("magic_quotes_gpc"));
9+
?>
10+
--EXPECT--
11+
string(1) "1"

0 commit comments

Comments
 (0)