Skip to content

Commit 4876148

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-21023: CURLOPT_XFERINFOFUNCTION with invalid callback crash.
2 parents 5dd9d2a + 2b89919 commit 4876148

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

ext/curl/interface.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ static int curl_fnmatch(void *ctx, const char *pattern, const char *string)
575575
zval argv[3];
576576
zval retval;
577577

578+
if (!ZEND_FCC_INITIALIZED(ch->handlers.fnmatch)) {
579+
return rval;
580+
}
581+
578582
GC_ADDREF(&ch->std);
579583
ZVAL_OBJ(&argv[0], &ch->std);
580584
ZVAL_STRING(&argv[1], pattern);
@@ -606,6 +610,9 @@ static int curl_progress(void *clientp, double dltotal, double dlnow, double ult
606610
fprintf(stderr, "curl_progress() called\n");
607611
fprintf(stderr, "clientp = %x, dltotal = %f, dlnow = %f, ultotal = %f, ulnow = %f\n", clientp, dltotal, dlnow, ultotal, ulnow);
608612
#endif
613+
if (!ZEND_FCC_INITIALIZED(ch->handlers.progress)) {
614+
return rval;
615+
}
609616

610617
zval args[5];
611618
zval retval;
@@ -644,6 +651,9 @@ static int curl_xferinfo(void *clientp, curl_off_t dltotal, curl_off_t dlnow, cu
644651
fprintf(stderr, "curl_xferinfo() called\n");
645652
fprintf(stderr, "clientp = %x, dltotal = %ld, dlnow = %ld, ultotal = %ld, ulnow = %ld\n", clientp, dltotal, dlnow, ultotal, ulnow);
646653
#endif
654+
if (!ZEND_FCC_INITIALIZED(ch->handlers.xferinfo)) {
655+
return rval;
656+
}
647657

648658
zval argv[5];
649659
zval retval;

ext/curl/tests/gh21023.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-21023 (crash with CURLOPT_XFERINFOFUNCTION set with an invalid callback)
3+
--EXTENSIONS--
4+
curl
5+
--FILE--
6+
<?php
7+
include 'server.inc';
8+
$host = curl_cli_server_start();
9+
$url = "{$host}/get.inc";
10+
$ch = curl_init($url);
11+
curl_setopt($ch, CURLOPT_NOPROGRESS, 0);
12+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
13+
curl_setopt($ch, CURLOPT_XFERINFOFUNCTION, null);
14+
curl_exec($ch);
15+
$ch = curl_init($url);
16+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
17+
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, null);
18+
curl_exec($ch);
19+
$ch = curl_init($url);
20+
curl_setopt($ch, CURLOPT_WILDCARDMATCH, 1);
21+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
22+
curl_setopt($ch, CURLOPT_FNMATCH_FUNCTION, null);
23+
curl_exec($ch);
24+
echo "OK", PHP_EOL;
25+
?>
26+
--EXPECT--
27+
OK

0 commit comments

Comments
 (0)