xref: /PHP-8.3/ext/curl/tests/bug76675.phpt (revision 47d47880)
1--TEST--
2Bug #76675 (Segfault with H2 server push write/writeheader handlers)
3--EXTENSIONS--
4curl
5--SKIPIF--
6<?php
7include 'skipif-nocaddy.inc';
8
9$curl_version = curl_version();
10if ($curl_version['version_number'] < 0x080100) {
11    exit("skip: test may crash with curl < 8.1.0");
12}
13?>
14--FILE--
15<?php
16$transfers = 1;
17$callback = function($parent, $passed) use (&$transfers) {
18    curl_setopt($passed, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
19        echo "Received ".strlen($data);
20        return strlen($data);
21    });
22    $transfers++;
23    return CURL_PUSH_OK;
24};
25$mh = curl_multi_init();
26curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
27curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $callback);
28$ch = curl_init();
29curl_setopt($ch, CURLOPT_URL, 'https://localhost/serverpush');
30curl_setopt($ch, CURLOPT_HTTP_VERSION, 3);
31curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
32curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
33curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
34curl_multi_add_handle($mh, $ch);
35$active = null;
36do {
37    $status = curl_multi_exec($mh, $active);
38    do {
39        $info = curl_multi_info_read($mh);
40        if (false !== $info && $info['msg'] == CURLMSG_DONE) {
41            $handle = $info['handle'];
42            if ($handle !== null) {
43                $transfers--;
44                curl_multi_remove_handle($mh, $handle);
45                curl_close($handle);
46            }
47        }
48    } while ($info);
49} while ($transfers);
50curl_multi_close($mh);
51?>
52--EXPECTREGEX--
53(Received \d+)+
54