Skip to content

Commit 2e263d2

Browse files
committed
Merge branch 'PHP-8.4'
2 parents 18ab3b9 + 42f8776 commit 2e263d2

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

ext/curl/interface.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,12 +1629,17 @@ static bool php_curl_set_callable_handler(zend_fcall_info_cache *const handler_f
16291629
}
16301630

16311631

1632-
#define HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(curl_ptr, constant_no_function, handler_type) \
1632+
#define HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(curl_ptr, constant_no_function, handler_type, default_method) \
16331633
case constant_no_function##FUNCTION: { \
16341634
bool result = php_curl_set_callable_handler(&curl_ptr->handlers.handler_type->fcc, zvalue, is_array_config, #constant_no_function "FUNCTION"); \
16351635
if (!result) { \
1636+
curl_ptr->handlers.handler_type->method = default_method; \
16361637
return FAILURE; \
16371638
} \
1639+
if (!ZEND_FCC_INITIALIZED(curl_ptr->handlers.handler_type->fcc)) { \
1640+
curl_ptr->handlers.handler_type->method = default_method; \
1641+
return SUCCESS; \
1642+
} \
16381643
curl_ptr->handlers.handler_type->method = PHP_CURL_USER; \
16391644
break; \
16401645
}
@@ -1657,9 +1662,9 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
16571662

16581663
switch (option) {
16591664
/* Callable options */
1660-
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_WRITE, write);
1661-
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_HEADER, write_header);
1662-
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_READ, read);
1665+
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_WRITE, write, PHP_CURL_STDOUT);
1666+
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_HEADER, write_header, PHP_CURL_IGNORE);
1667+
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_READ, read, PHP_CURL_DIRECT);
16631668

16641669
HANDLE_CURL_OPTION_CALLABLE(ch, CURLOPT_PROGRESS, handlers.progress, curl_progress);
16651670
HANDLE_CURL_OPTION_CALLABLE(ch, CURLOPT_XFERINFO, handlers.xferinfo, curl_xferinfo);

ext/curl/tests/gh16359.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-16359 - 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+
?>
15+
--EXPECT--
16+
test

0 commit comments

Comments
 (0)