From: scope at planetavent dot de Operating system: Linux, Windows PHP version: 5.3.1 PHP Bug Type: Program Execution Bug description: exec() adds single byte twice to $output array
Description: ------------ If exec is used to start a command that outputs only a single byte, and if the $output array is used, the byte is added twice to the output array. Tested with php 5.3.1 in cli mode on Windows 2003 Server and Ubuntu 9.10 Server. This behaviour was introduced with bugfix to #49847: >From exec.c:125 while (php_stream_get_line(stream, b, EXEC_INPUT_BUF, &bufl)) { ... if (b[bufl - 1] != '\n' && !php_stream_eof(stream)) { ... continue; If only a single byte is read, php_stream_eof(stream) returns true, thus no second loop will take place. After line 149: while (l-- && isspace(((unsigned char *)buf)[l])); buflen is 1 and l is 0, therefor line 160: if ((type == 2 && bufl && !l) || type != 2) { yields true and the buffer is added to the output array, again. Reproduce code: --------------- <?php $command = "echo x"; exec( $command, $output ); print_r( $output ); Expected result: ---------------- Array ( [0] => x ) Actual result: -------------- Array ( [0] => x [1] => x ) -- Edit bug report at http://bugs.php.net/?id=50732&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50732&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50732&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50732&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50732&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50732&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50732&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50732&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50732&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50732&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50732&r=support Expected behavior: http://bugs.php.net/fix.php?id=50732&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50732&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50732&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50732&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50732&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=50732&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50732&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50732&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50732&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50732&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50732&r=mysqlcfg