Skip to content

Commit d1fd543

Browse files
committed
Fixed bug #61043 (Regression in magic_quotes_gpc fix for CVE-2012-0831)
1 parent 4a6d9b3 commit d1fd543

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

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

0 commit comments

Comments
 (0)