ID:               39215
 Updated by:       [EMAIL PROTECTED]
 Reported By:      tstarling at wikimedia dot org
 Status:           Feedback
 Bug Type:         Streams related
 Operating System: Linux & Windows
 PHP Version:      5CVS-2006-10-20 (CVS)
 New Comment:

.. and the "double close" is actually much easier to reproduce with
just:
<?php
$s = fopen("php://stdin", "r");
?>
On shutdown both $s and STDIN constant are destroyed, but they both
point to the same resource. It's reproducible only with CLI, though.



Previous Comments:
------------------------------------------------------------------------

[2006-10-20 16:31:56] [EMAIL PROTECTED]

How do you expect to work then?
You should be able to close it AND you shouldn't be able to close it in
the same time. These two statements are mutually exclusive.

And I can't reproduce the segfault, so please provide a backtrace.

------------------------------------------------------------------------

[2006-10-20 16:07:18] tstarling at wikimedia dot org

Description:
------------
The stream created by fopen('php://stdin','r') has inappropriate
ownership semantics. It closes the underlying FD when it is destroyed,
despite the fact that it didn't open it. If you create two distinct
streams which refer to the same FD, as demonstrated below, you can
cause a double-close, which causes a segfault on Windows XP. 

This may well be a regression caused by the fix of bug #38199

Reproduce code:
---------------
<?php

function foo() {
        static $stdin;
        $stdin = fopen( 'php://stdin', 'r' );
        return fgets( $stdin );
}
print foo();

?>


Expected result:
----------------
FD 0 should not be closed.

Actual result:
--------------
You can see that FD 0 is closed using strace. In fact it is closed
twice, once by the static variable destructor and once by the
destructor of the STDIN constant.

[EMAIL PROTECTED]:~]$ strace -e trace=close php -n
stdin-test.php
close(3)                                = 0
close(3)                                = 0

...

hello
hello
close(0)                                = 0
close(0)                                = -1 EBADF (Bad file
descriptor)
Process 28429 detached



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39215&edit=1

Reply via email to