From:             tstarling at wikimedia dot org
Operating system: Linux & Windows
PHP version:      5CVS-2006-10-20 (CVS)
PHP Bug Type:     Streams related
Bug description:  Inappropriate close of stdin/stdout/stderr

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 bug report at http://bugs.php.net/?id=39215&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39215&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39215&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39215&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39215&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39215&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39215&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39215&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39215&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39215&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39215&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39215&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39215&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39215&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39215&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39215&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39215&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39215&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39215&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39215&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39215&r=mysqlcfg

Reply via email to