mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
php_socket_errno() may return a stale value when recv returns a value >= 0. As such, the liveness check is wrong. This is the same bug as #70198 (fixed in GH-1456). So we fix it in the same way. Closes GH-13895.
50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
--TEST--
|
|
GH-13860 (Incorrect PHP_STREAM_OPTION_CHECK_LIVENESS case in ext/openssl/xp_ssl.c - causing use of dead socket)
|
|
--EXTENSIONS--
|
|
openssl
|
|
--SKIPIF--
|
|
<?php
|
|
if (!function_exists("proc_open")) die("skip no proc_open");
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
$serverCode = <<<'CODE'
|
|
$serverUri = "tcp://127.0.0.1:64325";
|
|
$serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
|
|
$serverCtx = stream_context_create();
|
|
|
|
$server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
|
|
phpt_notify();
|
|
|
|
$client = @stream_socket_accept($server);
|
|
if ($client) {
|
|
fwrite($client, "xx");
|
|
phpt_wait();
|
|
fclose($client);
|
|
}
|
|
CODE;
|
|
|
|
$clientCode = <<<'CODE'
|
|
$serverUri = "tcp://127.0.0.1:64325";
|
|
$clientFlags = STREAM_CLIENT_CONNECT;
|
|
|
|
phpt_wait();
|
|
$fp = stream_socket_client($serverUri);
|
|
stream_set_blocking($fp, false);
|
|
|
|
fread($fp, 2);
|
|
|
|
phpt_notify();
|
|
while (!($in = fread($fp, 2))) {
|
|
usleep(1000);
|
|
}
|
|
var_dump(feof($fp));
|
|
fclose($fp);
|
|
CODE;
|
|
|
|
include 'ServerClientTestCase.inc';
|
|
ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
|
|
?>
|
|
--EXPECT--
|
|
bool(true)
|