Bug #74252 [NEW]: Non-existent STDIN duplicates FD 0 instead of registering it as closed stream

From: Date: Wed, 15 Mar 2017 14:55:35 +0000
Subject: Bug #74252 [NEW]: Non-existent STDIN duplicates FD 0 instead of registering it as closed stream
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207855@lists.php.net to get a copy of this message
From:             kelunik
Operating system: Linux
PHP version:      Irrelevant
Package:          Streams related
Bug Type:         Bug
Bug description:Non-existent STDIN duplicates FD 0 instead of registering it as closed stream

Description:
------------
If no STDIN exists, STDIN is still registered as FD 0 instead of a
closed stream. This results in scripts without STDIN reading from
/dev/urandom, because that's opened and just uses the next free FD.

Instead of duplicating the FD in
https://github.com/php/php-src/blob/16ae9f82e82e2aea5d7deaf8f9a9c825a56dfcc1/ext/standard/php_fopen_wrapper.c#L265
it should be registered as closed stream.

See also https://github.com/reactphp/stream/issues/81.

Test script:
---------------
php -r 'var_dump(!!fstat(STDIN));passthru("ls -o
/proc/".getmypid()."/fd");' <&-

Expected result:
----------------
STDIN should be a closed stream instead of /dev/urandom

Actual result:
--------------
STDIN is /dev/urandom

-- 
Edit bug report at https://bugs.php.net/bug.php?id=74252&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74252&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74252&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74252&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74252&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74252&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74252&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74252&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74252&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74252&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74252&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74252&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74252&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74252&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74252&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74252&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74252&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74252&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74252&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74252&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74252&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#207855) next »