]> granicus.if.org Git - php/commitdiff
Fixed bug #26176 (Fixed handling of numeric keys in INI files).
authorIlia Alshanetsky <iliaa@php.net>
Mon, 10 Nov 2003 04:12:38 +0000 (04:12 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 10 Nov 2003 04:12:38 +0000 (04:12 +0000)
ext/standard/basic_functions.c

index 60f01bf7d9f9cf2224909f405f656a11c792bc57..3e38200075fbac21ba920ef88f0b3ce45aa2caa3 100644 (file)
@@ -2877,7 +2877,12 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
                        *element = *arg2;
                        zval_copy_ctor(element);
                        INIT_PZVAL(element);
-                       zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL);
+                       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);
+                       }
                        break;
 
                case ZEND_INI_PARSER_POP_ENTRY:
@@ -2889,14 +2894,27 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
                                break;
                        }
 
-                       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);
+                       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);
+                                       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 {
-                               hash = *find_hash;
+                               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;
+                               }
                        }
 
                        ALLOC_ZVAL(element);
@@ -2919,11 +2937,12 @@ 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));
-               zend_hash_update(       Z_ARRVAL_P(arr),
-                                                       Z_STRVAL_P(arg1),
-                                                       Z_STRLEN_P(arg1)+1,
-                                                       &BG(active_ini_file_section),
-                                                       sizeof(zval *), NULL);
+               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);
+               }
        } else if (arg2) {
                zval *active_arr;