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