xref: /PHP-8.4/ext/openssl/tests/gh13860.phpt (revision 070779c8)
1--TEST--
2GH-13860 (Incorrect PHP_STREAM_OPTION_CHECK_LIVENESS case in ext/openssl/xp_ssl.c - causing use of dead socket)
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!function_exists("proc_open")) die("skip no proc_open");
8?>
9--FILE--
10<?php
11$serverCode = <<<'CODE'
12    $serverUri = "tcp://127.0.0.1:64326";
13    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
14    $serverCtx = stream_context_create();
15
16    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
17    phpt_notify();
18
19    $client = @stream_socket_accept($server);
20    if ($client) {
21        phpt_wait();
22        fwrite($client, "xx");
23        fclose($client);
24        phpt_notify();
25    }
26CODE;
27
28$clientCode = <<<'CODE'
29    $serverUri = "tcp://127.0.0.1:64326";
30    $clientFlags = STREAM_CLIENT_CONNECT;
31
32    phpt_wait();
33    $fp = stream_socket_client($serverUri);
34    stream_set_blocking($fp, false);
35
36    fread($fp, 2);
37
38    phpt_notify();
39    while (!($in = fread($fp, 2))) {
40        usleep(1000);
41    }
42    phpt_wait();
43    var_dump(feof($fp));
44    fclose($fp);
45CODE;
46
47include 'ServerClientTestCase.inc';
48ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
49?>
50--EXPECT--
51bool(true)
52