bjori Wed Nov 14 14:42:26 2007 UTC Added files: (Branch: PHP_5_3) /php-src/ext/standard/tests/general_functions bug43293_1.phpt bug43293_2.phpt bug43293_3.phpt
Modified files: /php-src/ext/standard basic_functions.c Log: Fixed bug#43293 (Multiple segfaults in getopt()) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.64.2.10&r2=1.725.2.31.2.64.2.11&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.64.2.10 php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.11 --- php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.10 Tue Nov 6 12:12:58 2007 +++ php-src/ext/standard/basic_functions.c Wed Nov 14 14:42:25 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.10 2007/11/06 12:12:58 helly Exp $ */ +/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.11 2007/11/14 14:42:25 bjori Exp $ */ #include "php.h" #include "php_streams.h" @@ -4552,11 +4552,11 @@ /* Get argv from the global symbol table. We calculate argc ourselves * 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)); @@ -4568,8 +4568,22 @@ zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args)); /* 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)); + while (zend_hash_get_current_data(Z_ARRVAL_PP(args), (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)); } @@ -4585,7 +4599,7 @@ if (p_longopts) { int count; - zval **arg; + zval **entry; count = zend_hash_num_elements(Z_ARRVAL_P(p_longopts)); @@ -4605,9 +4619,18 @@ zend_hash_internal_pointer_reset(Z_ARRVAL_P(p_longopts)); /* Iterate over the hash to construct the argv array. */ - while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts), (void **)&arg) == SUCCESS) { + while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts), (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; + } + opts->need_param = 0; - opts->opt_name = estrdup(Z_STRVAL_PP(arg)); + opts->opt_name = estrdup(Z_STRVAL_P(arg_ptr)); len = strlen(opts->opt_name); if ((len > 0) && (opts->opt_name[len - 1] == ':')) { opts->need_param++; @@ -4619,6 +4642,11 @@ } opts->opt_char = 0; opts++; + + if (arg_ptr != *entry) { + zval_dtor(&arg); + } + zend_hash_move_forward(Z_ARRVAL_P(p_longopts)); } } else { 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