Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/zend_ini_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ ZEND_API zend_result zend_parse_ini_file(zend_file_handle *fh, bool unbuffered_e

ini_parser_param.ini_parser_cb = ini_parser_cb;
ini_parser_param.arg = arg;
CG(ini_parser_param) = &ini_parser_param;

if (zend_ini_open_file_for_scanning(fh, scanner_mode) == FAILURE) {
return FAILURE;
}

CG(ini_parser_param) = &ini_parser_param;
CG(ini_parser_unbuffered_errors) = unbuffered_errors;
retval = ini_parse();

Expand Down
6 changes: 6 additions & 0 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,7 @@ PHP_FUNCTION(parse_ini_file)
zend_long scanner_mode = ZEND_INI_SCANNER_NORMAL;
zend_file_handle fh;
zend_ini_parser_cb_t ini_parser_cb;
zval prev_ini_file_section;

ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_PATH_STR(filename)
Expand All @@ -2540,6 +2541,7 @@ PHP_FUNCTION(parse_ini_file)
}

/* Set callback function */
ZVAL_COPY_VALUE(&prev_ini_file_section, &BG(active_ini_file_section));
if (process_sections) {
ZVAL_UNDEF(&BG(active_ini_file_section));
ini_parser_cb = (zend_ini_parser_cb_t) php_ini_parser_cb_with_sections;
Expand All @@ -2555,6 +2557,7 @@ PHP_FUNCTION(parse_ini_file)
zend_array_destroy(Z_ARR_P(return_value));
RETVAL_FALSE;
}
ZVAL_COPY_VALUE(&BG(active_ini_file_section), &prev_ini_file_section);
zend_destroy_file_handle(&fh);
}
/* }}} */
Expand All @@ -2567,6 +2570,7 @@ PHP_FUNCTION(parse_ini_string)
bool process_sections = 0;
zend_long scanner_mode = ZEND_INI_SCANNER_NORMAL;
zend_ini_parser_cb_t ini_parser_cb;
zval prev_ini_file_section;

ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_STRING(str, str_len)
Expand All @@ -2580,6 +2584,7 @@ PHP_FUNCTION(parse_ini_string)
}

/* Set callback function */
ZVAL_COPY_VALUE(&prev_ini_file_section, &BG(active_ini_file_section));
if (process_sections) {
ZVAL_UNDEF(&BG(active_ini_file_section));
ini_parser_cb = (zend_ini_parser_cb_t) php_ini_parser_cb_with_sections;
Expand All @@ -2597,6 +2602,7 @@ PHP_FUNCTION(parse_ini_string)
zend_array_destroy(Z_ARR_P(return_value));
RETVAL_FALSE;
}
ZVAL_COPY_VALUE(&BG(active_ini_file_section), &prev_ini_file_section);
efree(string);
}
/* }}} */
Expand Down
51 changes: 51 additions & 0 deletions ext/standard/tests/general_functions/gh25691.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
GH-25691 (Stack-use-after-return in ini_parse() with nested parse_ini_*() from a stream wrapper)
--CREDITS--
xuziqiang98
--FILE--
<?php
class W {
public $context;
private $done = false;

public function stream_open($path, $mode, $options, &$opened_path) {
var_dump(parse_ini_string("[sec]\nb=2", true));
return true;
}

public function stream_read($count) {
if ($this->done) {
return "";
}
$this->done = true;
return "a=1\n";
}

public function stream_eof() {
return true;
}

public function stream_stat() {
return [];
}

public function stream_set_option($option, $arg1, $arg2) {
return false;
}
}

stream_wrapper_register('ww', W::class);
var_dump(parse_ini_file('ww://x', true));
?>
--EXPECT--
array(1) {
["sec"]=>
array(1) {
["b"]=>
string(1) "2"
}
}
array(1) {
["a"]=>
string(1) "1"
}
Loading