From 80f8ad97fb14cd7f0623a5c34b6d6c9cdc4532f4 Mon Sep 17 00:00:00 2001 From: Jani Taskinen Date: Sun, 31 Aug 2008 00:19:50 +0000 Subject: [PATCH] MFH:- Fixed bug #45956 (parse_ini_file() does not return false with syntax errors in parsed file) --- ext/standard/basic_functions.c | 6 +++++- .../tests/file/parse_ini_file_error.phpt | 6 ++---- .../general_functions/parse_ini_file-win32.phpt | 16 ++++------------ .../tests/general_functions/parse_ini_file.phpt | 16 ++++------------ 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 0fc77d4cdf..253cdccc21 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -6359,7 +6359,11 @@ PHP_FUNCTION(parse_ini_file) fh.type = ZEND_HANDLE_FILENAME; array_init(return_value); - zend_parse_ini_file(&fh, 0, scanner_mode, ini_parser_cb, return_value TSRMLS_CC); + if (zend_parse_ini_file(&fh, 0, scanner_mode, ini_parser_cb, return_value TSRMLS_CC) == FAILURE) { + zend_hash_destroy(Z_ARRVAL_P(return_value)); + efree(Z_ARRVAL_P(return_value)); + RETURN_FALSE; + } } /* }}} */ diff --git a/ext/standard/tests/file/parse_ini_file_error.phpt b/ext/standard/tests/file/parse_ini_file_error.phpt index db63f2cdb6..9482df8a4d 100644 --- a/ext/standard/tests/file/parse_ini_file_error.phpt +++ b/ext/standard/tests/file/parse_ini_file_error.phpt @@ -42,12 +42,10 @@ bool(false) -- Testing parse_ini_file() function with more than expected no. of arguments -- Warning: parse_ini_file(%s): failed to open stream: No such file or directory in %s on line %d -array(0) { -} +bool(false) -- Testing parse_ini_file() function with a non-existent file -- Warning: parse_ini_file(%s): failed to open stream: No such file or directory in %s on line %d -array(0) { -} +bool(false) Done diff --git a/ext/standard/tests/general_functions/parse_ini_file-win32.phpt b/ext/standard/tests/general_functions/parse_ini_file-win32.phpt index cd7d9f8442..7a1d63010d 100644 --- a/ext/standard/tests/general_functions/parse_ini_file-win32.phpt +++ b/ext/standard/tests/general_functions/parse_ini_file-win32.phpt @@ -116,12 +116,10 @@ Warning: parse_ini_file() expects at most 3 parameters, 4 given in %s on line 7 bool(false) Warning: parse_ini_file(%sparse_ini_file.dat): failed to open stream: No such file or directory in %s.php on line 8 -array(0) { -} +bool(false) Warning: parse_ini_file(%sparse_ini_file.dat): failed to open stream: No such file or directory in %s.php on line 9 -array(0) { -} +bool(false) array(1) { ["test"]=> string(0) "" @@ -129,17 +127,11 @@ array(1) { Warning: parse error in %s on line %d in %s on line 20 -array(1) { - ["test"]=> - string(0) "" -} +bool(false) Warning: parse error in %s on line %d in %s on line 26 -array(1) { - ["test"]=> - string(4) "test" -} +bool(false) array(1) { ["test"]=> string(8) "new diff --git a/ext/standard/tests/general_functions/parse_ini_file.phpt b/ext/standard/tests/general_functions/parse_ini_file.phpt index 9aa30f9e69..65a29e0022 100644 --- a/ext/standard/tests/general_functions/parse_ini_file.phpt +++ b/ext/standard/tests/general_functions/parse_ini_file.phpt @@ -116,12 +116,10 @@ Warning: parse_ini_file() expects at most 3 parameters, 4 given in %sparse_ini_f bool(false) Warning: parse_ini_file(%sparse_ini_file.dat): failed to open stream: No such file or directory in %sparse_ini_file.php on line 8 -array(0) { -} +bool(false) Warning: parse_ini_file(%sparse_ini_file.dat): failed to open stream: No such file or directory in %sparse_ini_file.php on line 9 -array(0) { -} +bool(false) array(1) { ["test"]=> string(0) "" @@ -129,17 +127,11 @@ array(1) { Warning: syntax error, unexpected '=' in %sparse_ini_file.dat on line 2 in %sparse_ini_file.php on line 20 -array(1) { - ["test"]=> - string(0) "" -} +bool(false) Warning: syntax error, unexpected '=' in %sparse_ini_file.dat on line 2 in %sparse_ini_file.php on line 26 -array(1) { - ["test"]=> - string(4) "test" -} +bool(false) array(1) { ["test"]=> string(8) "new -- 2.40.0