Skip to content

Commit 6849c75

Browse files
committed
changes from feedback
we do not set curl (function) user handler if there is no actual callback.
1 parent 66646b5 commit 6849c75

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

Zend/zend_API.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,6 @@ 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-
}
852846
/* Need to copy trampolines as they get released after they are called */
853847
if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
854848
func = (zend_function*) emalloc(sizeof(zend_function));

ext/curl/interface.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,12 +1631,19 @@ static bool php_curl_set_callable_handler(zend_fcall_info_cache *const handler_f
16311631
}
16321632

16331633

1634-
#define HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(curl_ptr, constant_no_function, handler_type) \
1634+
#define HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(curl_ptr, constant_no_function, handler_type, default_method) \
16351635
case constant_no_function##FUNCTION: { \
16361636
bool result = php_curl_set_callable_handler(&curl_ptr->handlers.handler_type->fcc, zvalue, is_array_config, #constant_no_function "FUNCTION"); \
16371637
if (!result) { \
16381638
return FAILURE; \
16391639
} \
1640+
if (!curl_ptr->handlers.handler_type) { \
1641+
return SUCCESS; \
1642+
} \
1643+
if (!curl_ptr->handlers.handler_type->fcc.function_handler || !ZEND_FCC_INITIALIZED(curl_ptr->handlers.handler_type->fcc)) { \
1644+
curl_ptr->handlers.handler_type->method = default_method; \
1645+
return FAILURE; \
1646+
} \
16401647
curl_ptr->handlers.handler_type->method = PHP_CURL_USER; \
16411648
break; \
16421649
}
@@ -1659,9 +1666,9 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
16591666

16601667
switch (option) {
16611668
/* Callable options */
1662-
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_WRITE, write);
1663-
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_HEADER, write_header);
1664-
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_READ, read);
1669+
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_WRITE, write, PHP_CURL_STDOUT);
1670+
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_HEADER, write_header, PHP_CURL_IGNORE);
1671+
HANDLE_CURL_OPTION_CALLABLE_PHP_CURL_USER(ch, CURLOPT_READ, read, PHP_CURL_DIRECT);
16651672

16661673
HANDLE_CURL_OPTION_CALLABLE(ch, CURLOPT_PROGRESS, handlers.progress, curl_progress);
16671674
HANDLE_CURL_OPTION_CALLABLE(ch, CURLOPT_XFERINFO, handlers.xferinfo, curl_xferinfo);

ext/curl/tests/gh16359.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
GH-16360 - curl_setopt with CURLOPT_WRITEFUNCTION and no user fn
2+
GH-16359 - curl_setopt with CURLOPT_WRITEFUNCTION and no user fn
33
--EXTENSIONS--
44
curl
55
--FILE--
@@ -11,7 +11,6 @@ $ch = curl_init();
1111
curl_setopt($ch, CURLOPT_WRITEFUNCTION, null);
1212
curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file);
1313
curl_exec($ch);
14-
echo "DONE";
1514
?>
1615
--EXPECT--
17-
DONE
16+
test

0 commit comments

Comments
 (0)