bjori           Wed Nov 14 15:19:30 2007 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/standard/tests/general_functions       bug43293_1.phpt 
                                                        bug43293_2.phpt 
                                                        bug43293_3.phpt 

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/standard       basic_functions.c 
  Log:
   MFB5.3: Fixed bug#43293 (Multiple segfaults in getopt())
  
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1010&r2=1.2027.2.547.2.1011&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.1010 php-src/NEWS:1.2027.2.547.2.1011
--- php-src/NEWS:1.2027.2.547.2.1010    Tue Nov 13 20:08:04 2007
+++ php-src/NEWS        Wed Nov 14 15:19:29 2007
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2008, PHP 5.2.6
+- Fixed bug #43293 (Multiple segfaults in getopt()). (Hannes)
 - Fixed bug #43279 (pg_send_query_params() converts all elements in 'params' 
   to strings). (Ilia)
 - Fixed bug #43248 (backward compatibility break in realpath()). (Dmitry)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.66&r2=1.725.2.31.2.67&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.66 
php-src/ext/standard/basic_functions.c:1.725.2.31.2.67
--- php-src/ext/standard/basic_functions.c:1.725.2.31.2.66      Mon Oct 22 
07:37:20 2007
+++ php-src/ext/standard/basic_functions.c      Wed Nov 14 15:19:29 2007
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.725.2.31.2.66 2007/10/22 07:37:20 dmitry Exp $ */
+/* $Id: basic_functions.c,v 1.725.2.31.2.67 2007/11/14 15:19:29 bjori Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -4568,10 +4568,11 @@
         * in order to be on the safe side, even though it is also available
         * from the symbol table.
         */
-       if (zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), 
"argv", sizeof("argv"), (void **) &args) != FAILURE ||
-               zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void 
**) &args) != FAILURE) {
+       if ((zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), 
"argv", sizeof("argv"), (void **) &args) != FAILURE ||
+               zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void 
**) &args) != FAILURE) && Z_TYPE_PP(args) == IS_ARRAY
+       ) {
                int pos = 0;
-               zval **arg;
+               zval **entry;
 
                argc = zend_hash_num_elements(Z_ARRVAL_PP(args));
 
@@ -4586,8 +4587,22 @@
 
                /* Iterate over the hash to construct the argv array. */
                while (zend_hash_get_current_data(Z_ARRVAL_PP(args),
-                                                                               
  (void **)&arg) == SUCCESS) {
-                       argv[pos++] = estrdup(Z_STRVAL_PP(arg));
+                                                                               
  (void **)&entry) == SUCCESS) {
+                       zval arg, *arg_ptr = *entry;
+
+                       if (Z_TYPE_PP(entry) != IS_STRING) {
+                               arg = **entry;
+                               zval_copy_ctor(&arg);
+                               convert_to_string(&arg);
+                               arg_ptr = &arg;
+                       }
+
+                       argv[pos++] = estrdup(Z_STRVAL_P(arg_ptr));
+
+                       if (arg_ptr != *entry) {
+                               zval_dtor(&arg);
+                       }
+
                        zend_hash_move_forward(Z_ARRVAL_PP(args));
                }
 
@@ -4605,7 +4620,7 @@
 #ifdef HARTMUT_0
                int len, c = zend_hash_num_elements(Z_ARRVAL_P(p_longopts));
                struct option *p;
-               zval **arg;
+               zval **entry;
                char *name;
 
                longopts = (struct option *)ecalloc(c+1, sizeof(struct option));
@@ -4618,10 +4633,19 @@
 
                /* Iterate over the hash to construct the argv array. */
                while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts),
-                                                                               
  (void **)&arg) == SUCCESS) {
+                                                                               
  (void **)&entry) == SUCCESS) {
+                       zval arg, *arg_ptr = *entry;
+
+                       if (Z_TYPE_PP(entry) != IS_STRING) {
+                               arg = **entry;
+                               zval_copy_ctor(&arg);
+                               convert_to_string(&arg);
+                               arg_ptr = &arg;
+                       }
+
 
                        p->has_arg = 0;
-                       name = estrdup(Z_STRVAL_PP(arg));
+                       name = estrdup(Z_STRVAL_P(arg_ptr));
                        len = strlen(name);
                        if((len > 0) && (name[len-1] == ':')) {
                                p->has_arg++;
@@ -4636,6 +4660,10 @@
                        p->flag = NULL;
                        p->val = 0;
 
+                       if (arg_ptr != *entry) {
+                               zval_dtor(&arg);
+                       }
+
                        zend_hash_move_forward(Z_ARRVAL_P(p_longopts));
                        p++;
                }

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/bug43293_1.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/general_functions/bug43293_1.phpt
+++ php-src/ext/standard/tests/general_functions/bug43293_1.phpt

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/bug43293_2.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/general_functions/bug43293_2.phpt
+++ php-src/ext/standard/tests/general_functions/bug43293_2.phpt

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/bug43293_3.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/general_functions/bug43293_3.phpt
+++ php-src/ext/standard/tests/general_functions/bug43293_3.phpt

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to