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