From: Antony Dovgal Date: Tue, 26 Jun 2007 12:08:50 +0000 (+0000) Subject: fix #41445 (parse_ini_file() has a problem with certain types of integer as sections) X-Git-Tag: BEFORE_IMPORT_OF_MYSQLND~385 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3c372210bc96a688198d1a65bfdf02485761b84;p=php fix #41445 (parse_ini_file() has a problem with certain types of integer as sections) --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index ec87b2f772..8a4d6a2f09 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -6122,7 +6122,7 @@ PHP_FUNCTION(move_uploaded_file) static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, zval *arr) { - zval *element; + zval *element, name; TSRMLS_FETCH(); switch (callback_type) { @@ -6136,29 +6136,17 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, *element = *arg2; zval_copy_ctor(element); INIT_PZVAL(element); + + name = *arg1; + zval_copy_ctor(&name); + INIT_PZVAL(&name); + if (UG(unicode)) { convert_to_unicode_with_converter(element, UG(utf8_conv)); + convert_to_unicode_with_converter(&name, UG(utf8_conv)); } - if (is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) != IS_LONG) { - zstr key; - int key_len; - - if (UG(unicode)) { - if (zend_string_to_unicode(UG(utf8_conv), &key.u, &key_len, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) TSRMLS_CC) == FAILURE) { - return; - } - } else { - key.s = Z_STRVAL_P(arg1); - key_len = Z_STRLEN_P(arg1); - } - zend_u_hash_update(Z_ARRVAL_P(arr), ZEND_STR_TYPE, key, key_len+1, &element, sizeof(zval *), NULL); - if (UG(unicode)) { - efree(key.u); - } - } 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_u_symtable_update(Z_ARRVAL_P(arr), ZEND_STR_TYPE, Z_UNIVAL(name), Z_UNILEN(name)+1, &element, sizeof(zval *), NULL); + zval_dtor(&name); break; case ZEND_INI_PARSER_POP_ENTRY: @@ -6170,7 +6158,18 @@ 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 (!(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); + INIT_PZVAL(hash); + array_init(hash); + + zend_hash_index_update(Z_ARRVAL_P(arr), key, &hash, sizeof(zval *), NULL); + } else { + hash = *find_hash; + } + } else { zstr key; int key_len; @@ -6196,17 +6195,6 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, if (UG(unicode)) { efree(key.u); } - } else { - 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); - INIT_PZVAL(hash); - array_init(hash); - - zend_hash_index_update(Z_ARRVAL_P(arr), key, &hash, sizeof(zval *), NULL); - } else { - hash = *find_hash; - } } if (Z_TYPE_P(hash) != IS_ARRAY) { @@ -6233,31 +6221,21 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, static void php_ini_parser_cb_with_sections(zval *arg1, zval *arg2, int callback_type, zval *arr) { + zval name; TSRMLS_FETCH(); 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) { - zstr key; - int key_len; + name = *arg1; + zval_copy_ctor(&name); + INIT_PZVAL(&name); - if (UG(unicode)) { - if (zend_string_to_unicode(UG(utf8_conv), &key.u, &key_len, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) TSRMLS_CC) == FAILURE) { - return; - } - } else { - key.s = Z_STRVAL_P(arg1); - key_len = Z_STRLEN_P(arg1); - } - zend_u_hash_update(Z_ARRVAL_P(arr), ZEND_STR_TYPE, key, key_len+1, &BG(active_ini_file_section), sizeof(zval *), NULL); - if (UG(unicode)) { - efree(key.u); - } - } 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); + if (UG(unicode)) { + convert_to_unicode_with_converter(&name, UG(utf8_conv)); } + zend_u_symtable_update(Z_ARRVAL_P(arr), ZEND_STR_TYPE, Z_UNIVAL(name), Z_UNILEN(name)+1, &BG(active_ini_file_section), sizeof(zval *), NULL); + zval_dtor(&name); } else if (arg2) { zval *active_arr; diff --git a/ext/standard/tests/general_functions/bug41445.phpt b/ext/standard/tests/general_functions/bug41445.phpt new file mode 100644 index 0000000000..49d4415ed2 --- /dev/null +++ b/ext/standard/tests/general_functions/bug41445.phpt @@ -0,0 +1,113 @@ +--TEST-- +Bug #41445 (parse_ini_file() function parses octal numbers in section names) +--FILE-- + +--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 +--UEXPECTF-- +array(2) { + [u"001099030277"]=> + array(1) { + [u"option1"]=> + unicode(1) "1" + } + [u"011099030277"]=> + array(1) { + [u"option2"]=> + unicode(1) "1" + } +} +array(2) { + [u"option1"]=> + unicode(1) "1" + [u"option2"]=> + unicode(1) "1" +} +array(2) { + [u"23.44"]=> + array(1) { + [u"option1"]=> + unicode(1) "1" + } + [u"9633337363542736472364"]=> + array(1) { + [u"option2"]=> + unicode(1) "1" + } +} +array(2) { + [u"option1"]=> + unicode(1) "1" + [u"option2"]=> + unicode(1) "1" +} +Done diff --git a/ext/standard/tests/general_functions/bug41445_1.phpt b/ext/standard/tests/general_functions/bug41445_1.phpt new file mode 100644 index 0000000000..3ed35d339f --- /dev/null +++ b/ext/standard/tests/general_functions/bug41445_1.phpt @@ -0,0 +1,81 @@ +--TEST-- +Bug #41445 (parse_ini_file() function parses octal numbers in section names) - 2 +--FILE-- + +--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 +--UEXPECTF-- +array(3) { + [u"2454.33"]=> + array(1) { + [u"09"]=> + unicode(1) "1" + } + [9876543]=> + array(1) { + [u"098765434567876543"]=> + unicode(1) "1" + } + [u"09876543"]=> + array(1) { + [u"987654345678765432456798765434567876543"]=> + unicode(1) "1" + } +} +array(3) { + [u"09"]=> + unicode(1) "1" + [u"098765434567876543"]=> + unicode(1) "1" + [u"987654345678765432456798765434567876543"]=> + unicode(1) "1" +} +Done