php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35079 stream_set_blocking(true) toggles, not enables blocking
Submitted: 2005-11-03 05:55 UTC Modified: 2005-11-17 15:20 UTC
From: askalski at gmail dot com Assigned: wez (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5CVS-2005-11-03 (snap) OS: linux
Private report: No CVE-ID: None
 [2005-11-03 05:55 UTC] askalski at gmail dot com
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-03 18:56 UTC] askalski at gmail dot com
Still broken. (php-200511031730)
 [2005-11-03 21:43 UTC] sniper@php.net
Assigned to the author of streams.
 [2005-11-11 22:32 UTC] tony2001@php.net
Wez, the proposed solution looks good to me.
Please check it out.
 [2005-11-17 15:20 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC