]> granicus.if.org Git - php/commitdiff
fix #35713 (getopt() returns array with numeric strings when passed options like...
authorAntony Dovgal <tony2001@php.net>
Fri, 16 Dec 2005 20:09:16 +0000 (20:09 +0000)
committerAntony Dovgal <tony2001@php.net>
Fri, 16 Dec 2005 20:09:16 +0000 (20:09 +0000)
NEWS
ext/standard/basic_functions.c

diff --git a/NEWS b/NEWS
index 1d179f8e1b037e94b194d220bab37c7b999d244a..4cd6cb923e8df7810fcd211888ea6e05d9f14b11 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,8 @@ PHP                                                                        NEWS
 - Fixed many bugs in OCI8. (Tony)
 - Fixed crash and leak in mysqli when using 4.1.x client libraries and
   connecting to 5.x server. (Andrey)
+- Fixed bug #35713 (getopt() returns array with numeric strings when passed 
+  options like '-1'). (Tony)
 - Fixed bug #35694 (Improved error message for invalid fetch mode). (Ilia)
 - Fixed bug #35692 (iconv_mime_decode() segmentation fault; with libiconv 
   only). (Tony)
index 604ddf091de52f4ecd5e37e46fd628c72ec9fc88..583d7bdbc860c235a1e5ddd3bfb26f874e44bd48 100644 (file)
@@ -1568,6 +1568,7 @@ PHP_FUNCTION(getopt)
        char *optname;
        int argc = 0, options_len = 0, o;
        zval *val, **args = NULL, *p_longopts = NULL;
+       int optname_len = 0;
 #ifdef HARTMUT_0
        struct option *longopts = NULL;
        int longindex = 0;
@@ -1701,14 +1702,28 @@ PHP_FUNCTION(getopt)
                }
 
                /* Add this option / argument pair to the result hash. */
-               if(zend_hash_find(HASH_OF(return_value), optname, strlen(optname)+1, (void **)&args) != FAILURE) {
-                       if(Z_TYPE_PP(args) != IS_ARRAY) {
-                               convert_to_array_ex(args);
-                       } 
-                       zend_hash_next_index_insert(HASH_OF(*args),  (void *)&val, sizeof(zval *), NULL);
+               optname_len = strlen(optname);
+               if (!(optname_len > 1 && optname[0] == '0') && is_numeric_string(optname, optname_len, NULL, NULL, 0) == IS_LONG) {
+                       /* numeric string */
+                       int optname_int = atoi(optname);
+                       if(zend_hash_index_find(HASH_OF(return_value), optname_int, (void **)&args) != FAILURE) {
+                               if(Z_TYPE_PP(args) != IS_ARRAY) {
+                                       convert_to_array_ex(args);
+                               } 
+                               zend_hash_next_index_insert(HASH_OF(*args),  (void *)&val, sizeof(zval *), NULL);
+                       } else {
+                               zend_hash_index_update(HASH_OF(return_value), optname_int, &val, sizeof(zval *), NULL);
+                       }
                } else {
-                       zend_hash_add(HASH_OF(return_value), optname, strlen(optname)+1, (void *)&val,
-                                                 sizeof(zval *), NULL);
+                       /* other strings */
+                       if(zend_hash_find(HASH_OF(return_value), optname, strlen(optname)+1, (void **)&args) != FAILURE) {
+                               if(Z_TYPE_PP(args) != IS_ARRAY) {
+                                       convert_to_array_ex(args);
+                               } 
+                               zend_hash_next_index_insert(HASH_OF(*args),  (void *)&val, sizeof(zval *), NULL);
+                       } else {
+                               zend_hash_add(HASH_OF(return_value), optname, strlen(optname)+1, (void *)&val, sizeof(zval *), NULL);
+                       }
                }
        }