#35079 [NEW]: stream_set_blocking(true) toggles, not enables blocking

From: Date: Thu, 03 Nov 2005 04:55:12 +0000
Subject: #35079 [NEW]: stream_set_blocking(true) toggles, not enables blocking
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-87448@lists.php.net to get a copy of this message
From: askalski at gmail dot com Operating system: linux PHP version: 5.0.5 PHP Bug Type: Filesystem function related Bug description: stream_set_blocking(true) toggles, not enables blocking Description: ------------ main/streams/plain_wrapper.c (5.0.5) main/streams.c (4.4 and earlier) In several places, the ^= operator is used to turn off a flag. This is incorrect. For example, stream_set_blocking() on a plain file hits this code in php_stdiop_set_option(): if (value) flags ^= O_NONBLOCK; else flags |= O_NONBLOCK; This should be: if (value) flags &= ~O_NONBLOCK; else flags |= O_NONBLOCK; The same error is repeated elsewhere in the code. Reproduce code: --------------- $fp = fopen("test", "w"); stream_set_blocking($fp, true); stream_set_blocking($fp, true); stream_set_blocking($fp, true); stream_set_blocking($fp, true); fclose($fp); Expected result: ---------------- The stream should remain in blocking mode throughout the script execution. Actual result: -------------- Here is abridged strace output showing the errant behavior. Notice how O_NONBLOCK is being turned on and off alternately. open("/home/askalski/test", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4 fcntl64(4, F_SETFL, O_WRONLY|O_NONBLOCK) = 0 fcntl64(4, F_SETFL, O_WRONLY) = 0 fcntl64(4, F_SETFL, O_WRONLY|O_NONBLOCK) = 0 fcntl64(4, F_SETFL, O_WRONLY) = 0 close(4) = 0 -- Edit bug report at http://bugs.php.net/?id=35079&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35079&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35079&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35079&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=35079&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35079&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35079&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35079&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35079&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35079&r=support Expected behavior: http://bugs.php.net/fix.php?id=35079&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35079&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35079&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35079&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35079&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35079&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35079&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35079&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35079&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35079&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35079&r=mysqlcfg

« previous php.bugs (#87448) next »