xref: /PHP-8.0/ext/openssl/tests/bug73072.phpt (revision 9c144e0d)
1--TEST--
2Bug #73072: Invalid path SNI_server_certs causes segfault
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip openssl not loaded");
6if (!function_exists("proc_open")) die("skip no proc_open");
7?>
8--FILE--
9<?php
10$serverCode = <<<'CODE'
11    $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
12    $ctx = stream_context_create(['ssl' => [
13        'local_cert' => __DIR__ . '/domain1.pem',
14        'SNI_server_certs' => [
15            "domain1.com" => __DIR__ . "/sni_server_domain1.pem",
16            "domain2.com" => __DIR__ . "/not_existing.pem",
17        ]
18    ]]);
19
20    $server = stream_socket_server('tls://127.0.0.1:64322', $errno, $errstr, $flags, $ctx);
21
22    phpt_notify();
23    @stream_socket_accept($server, 3);
24    // if there is a segfault, this won't be called
25    fwrite(STDERR, "done\n");
26CODE;
27
28$clientCode = <<<'CODE'
29    $flags = STREAM_CLIENT_CONNECT;
30    $ctxArr = [
31        'cafile' => __DIR__ . '/sni_server_ca.pem',
32        'capture_peer_cert' => true
33    ];
34
35    phpt_wait();
36
37    $ctxArr['peer_name'] = 'domain1.com';
38    $ctx = stream_context_create(['ssl' => $ctxArr]);
39    @stream_socket_client("tls://127.0.0.1:64322", $errno, $errstr, 1, $flags, $ctx);
40CODE;
41
42include 'ServerClientTestCase.inc';
43ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
44?>
45--EXPECT--
46done
47