Bug #70122 [NEW]: stream_select() modifies array incorrectly if openssl is enabled
| From: | jake dot zatecky at gmail dot com | Date: | Thu, 23 Jul 2015 23:47:56 +0000 |
| Subject: | Bug #70122 [NEW]: stream_select() modifies array incorrectly if openssl is enabled | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-194663@lists.php.net to get a copy of this message | ||
From: jake dot zatecky at gmail dot com
Operating system: Windows 7/Windows Server 2008
PHP version: 5.6.11
Package: Streams related
Bug Type: Bug
Bug description:stream_select() modifies array incorrectly if openssl is enabled
Description:
------------
I have determined that the stream_select() function modifies the $read
variable incorrectly when php_openssl is loaded in more recent versions
of PHP. For example, when running a listener with PHP 5.6.11 on port
8000 and using telnet, stream_select() returns the correct number of
streams that received connection (1), but both the $read and $write
arrays returned are in fact empty.
This issue disappears if php_openssl is not loaded, or if you use PHP
5.6.6 (x64 thread-safe). There are several related bugs, but it would
appear that they address different issues.
I have verified this issue occurs identically on both PHP 5.6.9 and PHP
5.6.11 on a Windows 7 machine and Server 2008 R2 machine; it may occur
on other operating systems as well. Both versions are 64bit and
thread-safe. I used the same .ini configuration on each of the three
versions.
See the test code below to reproduce this behavior. Make sure
php_openssl.dll is loaded, run the PHP listener, and telnet the
localhost port.
E.g.:
$ php listener.php
Then, in a separate terminal, run something similar to the following:
$ telnet localhost 8000
Test script:
---------------
<?php
$socket = stream_socket_server('tcp://0.0.0.0:8000', $errno, $errstr);
stream_set_blocking($socket, 0);
if (!$socket) {
echo "$errstr ($errno)\n";
} else {
$read = [$socket];
$write = [];
$except = null;
$num = stream_select($read, $write, $except, null, null);
// On PHP 5.6.9/5.6.11: int(1) and array(0) {}
// On PHP 5.6.6 : int(1) and array(1) { [0] => ... }
var_dump($num, $read);
fclose($socket);
}
Expected result:
----------------
The $read variable should contain one element:
array(1) {
[0]=>
resource(5) of type (stream)
}
This is returned using PHP 5.6.6 or when openssl is disabled.
Actual result:
--------------
On PHP 5.6.9 and PHP 5.6.11, when openssl is loaded, the following is
outputted instead:
int(1)
array(0) {
}
--
Edit bug report at https://bugs.php.net/bug.php?id=70122&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70122&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70122&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70122&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70122&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70122&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70122&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70122&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70122&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70122&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70122&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70122&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70122&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70122&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70122&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70122&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70122&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70122&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70122&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70122&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70122&r=mysqlcfg