php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70122 stream_select() modifies array incorrectly if openssl is enabled
Submitted: 2015-07-23 23:47 UTC Modified: 2020-10-04 04:22 UTC
From: jake dot zatecky at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: Streams related
PHP Version: 5.6.11 OS: Windows 7/Windows Server 2008
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
8 + 21 = ?
Subscribe to this entry?

 
 [2015-07-23 23:47 UTC] jake dot zatecky at gmail dot com
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) {
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-22 09:39 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-09-22 09:39 UTC] cmb@php.net
Works for me as expected on Windows 10 with current PHP 7.3 and
7.4. Can you still reproduce the issue with any of the actively
supported PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2020-10-04 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 03:01:28 2024 UTC