mirror of
https://github.com/php/php-src.git
synced 2024-11-24 10:24:11 +08:00
MFH: fix #41445 (parse_ini_file() has a problem with certain types of integer as sections)
This commit is contained in:
parent
7210ab5695
commit
ce22f44493
2
NEWS
2
NEWS
@ -84,6 +84,8 @@ PHP NEWS
|
||||
- Fixed bug #41527 (WDDX deserialize numeric string array key). (Matt, Ilia)
|
||||
- Fixed bug #41518 (file_exists() warns of open_basedir restriction on
|
||||
non-existent file). (Tony)
|
||||
- Fixed bug #41445 (parse_ini_file() has a problem with certain types of
|
||||
integer as sections). (Tony)
|
||||
- Fixed bug #41350 (my_thread_global_end() error during request shutdown
|
||||
on Windows). (Scott, Andrey)
|
||||
- Fixed bug #39330 (apache2handler does not call shutdown actions before
|
||||
|
@ -6130,12 +6130,7 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
|
||||
*element = *arg2;
|
||||
zval_copy_ctor(element);
|
||||
INIT_PZVAL(element);
|
||||
if (is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) != IS_LONG) {
|
||||
zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL);
|
||||
} else {
|
||||
ulong key = (ulong) zend_atoi(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1));
|
||||
zend_hash_index_update(Z_ARRVAL_P(arr), key, &element, sizeof(zval *), NULL);
|
||||
}
|
||||
zend_symtable_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL);
|
||||
break;
|
||||
|
||||
case ZEND_INI_PARSER_POP_ENTRY:
|
||||
@ -6147,17 +6142,7 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) != IS_LONG) {
|
||||
if (zend_hash_find(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void **) &find_hash) == FAILURE) {
|
||||
ALLOC_ZVAL(hash);
|
||||
INIT_PZVAL(hash);
|
||||
array_init(hash);
|
||||
|
||||
zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &hash, sizeof(zval *), NULL);
|
||||
} else {
|
||||
hash = *find_hash;
|
||||
}
|
||||
} else {
|
||||
if (!(Z_STRLEN_P(arg1) > 1 && Z_STRVAL_P(arg1)[0]=='0') && is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) == IS_LONG) {
|
||||
ulong key = (ulong) zend_atoi(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1));
|
||||
if (zend_hash_index_find(Z_ARRVAL_P(arr), key, (void **) &find_hash) == FAILURE) {
|
||||
ALLOC_ZVAL(hash);
|
||||
@ -6168,6 +6153,16 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
|
||||
} else {
|
||||
hash = *find_hash;
|
||||
}
|
||||
} else {
|
||||
if (zend_hash_find(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void **) &find_hash) == FAILURE) {
|
||||
ALLOC_ZVAL(hash);
|
||||
INIT_PZVAL(hash);
|
||||
array_init(hash);
|
||||
|
||||
zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &hash, sizeof(zval *), NULL);
|
||||
} else {
|
||||
hash = *find_hash;
|
||||
}
|
||||
}
|
||||
|
||||
if (Z_TYPE_P(hash) != IS_ARRAY) {
|
||||
@ -6196,12 +6191,7 @@ static void php_ini_parser_cb_with_sections(zval *arg1, zval *arg2, int callback
|
||||
if (callback_type == ZEND_INI_PARSER_SECTION) {
|
||||
MAKE_STD_ZVAL(BG(active_ini_file_section));
|
||||
array_init(BG(active_ini_file_section));
|
||||
if (is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) != IS_LONG) {
|
||||
zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &BG(active_ini_file_section), sizeof(zval *), NULL);
|
||||
} else {
|
||||
ulong key = (ulong) zend_atoi(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1));
|
||||
zend_hash_index_update(Z_ARRVAL_P(arr), key, &BG(active_ini_file_section), sizeof(zval *), NULL);
|
||||
}
|
||||
zend_symtable_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &BG(active_ini_file_section), sizeof(zval *), NULL);
|
||||
} else if (arg2) {
|
||||
zval *active_arr;
|
||||
|
||||
|
75
ext/standard/tests/general_functions/bug41445.phpt
Normal file
75
ext/standard/tests/general_functions/bug41445.phpt
Normal file
@ -0,0 +1,75 @@
|
||||
--TEST--
|
||||
Bug #41445 (parse_ini_file() function parses octal numbers in section names)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/bug41445.ini";
|
||||
|
||||
$data = <<<DATA
|
||||
[001099030277]
|
||||
option1 = yes
|
||||
|
||||
[011099030277]
|
||||
option2 = yes
|
||||
DATA;
|
||||
|
||||
file_put_contents($file, $data);
|
||||
|
||||
var_dump(parse_ini_file($file, TRUE));
|
||||
var_dump(parse_ini_file($file));
|
||||
|
||||
$data = <<<DATA
|
||||
[23.44]
|
||||
option1 = yes
|
||||
|
||||
[9633337363542736472364]
|
||||
option2 = yes
|
||||
DATA;
|
||||
|
||||
file_put_contents($file, $data);
|
||||
|
||||
var_dump(parse_ini_file($file, TRUE));
|
||||
var_dump(parse_ini_file($file));
|
||||
|
||||
@unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(2) {
|
||||
["001099030277"]=>
|
||||
array(1) {
|
||||
["option1"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
["011099030277"]=>
|
||||
array(1) {
|
||||
["option2"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
}
|
||||
array(2) {
|
||||
["option1"]=>
|
||||
string(1) "1"
|
||||
["option2"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
array(2) {
|
||||
["23.44"]=>
|
||||
array(1) {
|
||||
["option1"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
["9633337363542736472364"]=>
|
||||
array(1) {
|
||||
["option2"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
}
|
||||
array(2) {
|
||||
["option1"]=>
|
||||
string(1) "1"
|
||||
["option2"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
Done
|
54
ext/standard/tests/general_functions/bug41445_1.phpt
Normal file
54
ext/standard/tests/general_functions/bug41445_1.phpt
Normal file
@ -0,0 +1,54 @@
|
||||
--TEST--
|
||||
Bug #41445 (parse_ini_file() function parses octal numbers in section names) - 2
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/bug41445.ini";
|
||||
|
||||
$data = <<<DATA
|
||||
[2454.33]
|
||||
09 = yes
|
||||
|
||||
[9876543]
|
||||
098765434567876543 = yes
|
||||
|
||||
[09876543]
|
||||
987654345678765432456798765434567876543 = yes
|
||||
DATA;
|
||||
|
||||
file_put_contents($file, $data);
|
||||
|
||||
var_dump(parse_ini_file($file, TRUE));
|
||||
var_dump(parse_ini_file($file));
|
||||
|
||||
@unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(3) {
|
||||
["2454.33"]=>
|
||||
array(1) {
|
||||
["09"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
[9876543]=>
|
||||
array(1) {
|
||||
["098765434567876543"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
["09876543"]=>
|
||||
array(1) {
|
||||
["987654345678765432456798765434567876543"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
}
|
||||
array(3) {
|
||||
["09"]=>
|
||||
string(1) "1"
|
||||
["098765434567876543"]=>
|
||||
string(1) "1"
|
||||
["987654345678765432456798765434567876543"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
Done
|
Loading…
Reference in New Issue
Block a user