Skip to content

Commit 32ae716

Browse files
pmmaganikic
authored andcommitted
Fixed bug #76675
Leave a reference to the resource in the php_curl.
1 parent 61cfa34 commit 32ae716

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PHP NEWS
55
- Core:
66
. Fixed bug #77339 (__callStatic may get incorrect arguments). (Dmitry)
77

8+
- Curl:
9+
. Fixed bug #76675 (Segfault with H2 server push). (Pedro Magalhães)
10+
811
- GD:
912
. Fixed bug #73281 (imagescale(…, IMG_BILINEAR_FIXED) can cause black border).
1013
(cmb)

ext/curl/multi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_hea
509509
Z_ADDREF_P(pz_parent_ch);
510510

511511
res = zend_register_resource(ch, le_curl);
512+
ch->res = res;
512513
ZVAL_RES(&pz_ch, res);
513514

514515
size_t i;

ext/curl/tests/bug76675.phpt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
Bug #76675 (Segfault with H2 server push write/writeheader handlers)
3+
--SKIPIF--
4+
<?php
5+
include 'skipif.inc';
6+
if (getenv("SKIP_ONLINE_TESTS")) {
7+
die("skip online test");
8+
}
9+
$curl_version = curl_version();
10+
if ($curl_version['version_number'] < 0x073d00) {
11+
exit("skip: test may crash with curl < 7.61.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();
26+
curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
27+
curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $callback);
28+
$ch = curl_init();
29+
curl_setopt($ch, CURLOPT_URL, 'https://http2.golang.org/serverpush');
30+
curl_setopt($ch, CURLOPT_HTTP_VERSION, 3);
31+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
32+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
33+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
34+
curl_multi_add_handle($mh, $ch);
35+
$active = null;
36+
do {
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);
50+
curl_multi_close($mh);
51+
?>
52+
--EXPECTREGEX--
53+
(Received \d+)+

0 commit comments

Comments
 (0)