From: rabbitt at gmail dot com Operating system: Linux 2.6.13 PHP version: 4.4.1 PHP Bug Type: Reproducible crash Bug description: getopt() only usable once - with long options built in, causes segfault
Description: ------------ Without long options built into zif_getopt(), zif_getopt()'s calls to getopt() will only return a populated result once. The reason for this is that 'optind' does not get reset on each call to getopt(). optind is used to keep track of the most option processed internally in getopt(). Once getopt() has finished processing the options, optind remains at the last value it was set to (typically, at this point, optind == argc). The problem with this is that when getopt() is called a second time, it thinks that it's already finished with processing the options due to optind being equal to argc. Worse still, with long optoins built in (-DHARTMUT_0), it causes a segfault in glibc's getopt.c (function: _getopt_internal_r() - line 521 specifically). Reproduce code: --------------- create file called test.php and add: <?php print_r(@getopt('t', array('test'))); print_r(@getopt('t', array('test'))); ?> then run: php test.php -t Expected result: ---------------- Array ( [t] => ) Array ( [t] => ) Actual result: -------------- One of two things will happen: Array ( [t] => ) Array ( ) or: Array ( ) Segmentation fault (core dumped) -- Edit bug report at http://bugs.php.net/?id=35594&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=35594&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=35594&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=35594&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=35594&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35594&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35594&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35594&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35594&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35594&r=support Expected behavior: http://bugs.php.net/fix.php?id=35594&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35594&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35594&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35594&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35594&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35594&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35594&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35594&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35594&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35594&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35594&r=mysqlcfg