Skip to content

Commit 66646b5

Browse files
committed
Fix GH-16359 curl write callback crash on FCC usage w/o user function.
1 parent 25d0661 commit 66646b5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Zend/zend_API.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,12 @@ static zend_always_inline void zend_call_known_fcc(
843843
const zend_fcall_info_cache *fcc, zval *retval_ptr, uint32_t param_count, zval *params, HashTable *named_params)
844844
{
845845
zend_function *func = fcc->function_handler;
846+
if (UNEXPECTED(!func)) {
847+
if (retval_ptr) {
848+
ZVAL_UNDEF(retval_ptr);
849+
}
850+
return;
851+
}
846852
/* Need to copy trampolines as they get released after they are called */
847853
if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
848854
func = (zend_function*) emalloc(sizeof(zend_function));

ext/curl/tests/gh16359.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-16360 - curl_setopt with CURLOPT_WRITEFUNCTION and no user fn
3+
--EXTENSIONS--
4+
curl
5+
--FILE--
6+
<?php
7+
$log_file = tempnam(sys_get_temp_dir(), 'php-curl-CURLOPT_WRITEFUNCTION-trampoline');
8+
$fp = fopen($log_file, 'w+');
9+
fwrite($fp, "test");
10+
$ch = curl_init();
11+
curl_setopt($ch, CURLOPT_WRITEFUNCTION, null);
12+
curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file);
13+
curl_exec($ch);
14+
echo "DONE";
15+
?>
16+
--EXPECT--
17+
DONE

0 commit comments

Comments
 (0)