@@ -500,8 +500,8 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n)
500
500
}
501
501
502
502
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
503
- if (curl -> handlers .sshhostkey ) {
504
- zend_get_gc_buffer_add_zval (gc_buffer , & curl -> handlers .sshhostkey -> func_name );
503
+ if (ZEND_FCC_INITIALIZED ( curl -> handlers .sshhostkey ) ) {
504
+ zend_get_gc_buffer_add_fcc (gc_buffer , & curl -> handlers .sshhostkey );
505
505
}
506
506
#endif
507
507
@@ -750,39 +750,27 @@ static size_t curl_xferinfo(void *clientp, curl_off_t dltotal, curl_off_t dlnow,
750
750
static int curl_ssh_hostkeyfunction (void * clientp , int keytype , const char * key , size_t keylen )
751
751
{
752
752
php_curl * ch = (php_curl * )clientp ;
753
- php_curl_callback * t = ch -> handlers .sshhostkey ;
754
753
int rval = CURLKHMATCH_MISMATCH ; /* cancel connection in case of an exception */
755
754
756
755
#if PHP_CURL_DEBUG
757
756
fprintf (stderr , "curl_ssh_hostkeyfunction() called\n" );
758
757
fprintf (stderr , "clientp = %x, keytype = %d, key = %s, keylen = %zu\n" , clientp , keytype , key , keylen );
759
758
#endif
760
759
761
- zval argv [4 ];
760
+ zval args [4 ];
762
761
zval retval ;
763
- zend_result error ;
764
- zend_fcall_info fci ;
765
762
766
763
GC_ADDREF (& ch -> std );
767
- ZVAL_OBJ (& argv [0 ], & ch -> std );
768
- ZVAL_LONG (& argv [1 ], keytype );
769
- ZVAL_STRINGL (& argv [2 ], key , keylen );
770
- ZVAL_LONG (& argv [3 ], keylen );
764
+ ZVAL_OBJ (& args [0 ], & ch -> std );
765
+ ZVAL_LONG (& args [1 ], keytype );
766
+ ZVAL_STRINGL (& args [2 ], key , keylen );
767
+ ZVAL_LONG (& args [3 ], keylen );
771
768
772
- fci .size = sizeof (fci );
773
- ZVAL_COPY_VALUE (& fci .function_name , & t -> func_name );
774
- fci .object = NULL ;
775
- fci .retval = & retval ;
776
- fci .param_count = 4 ;
777
- fci .params = argv ;
778
- fci .named_params = NULL ;
769
+ ch -> in_callback = true;
770
+ zend_call_known_fcc (& ch -> handlers .sshhostkey , & retval , /* param_count */ sizeof (args ), args , /* named_params */ NULL );
771
+ ch -> in_callback = false;
779
772
780
- ch -> in_callback = 1 ;
781
- error = zend_call_function (& fci , & t -> fci_cache );
782
- ch -> in_callback = 0 ;
783
- if (error == FAILURE ) {
784
- php_error_docref (NULL , E_WARNING , "Cannot call the CURLOPT_SSH_HOSTKEYFUNCTION" );
785
- } else if (!Z_ISUNDEF (retval )) {
773
+ if (!Z_ISUNDEF (retval )) {
786
774
_php_curl_verify_handlers (ch , /* reporterror */ true);
787
775
if (Z_TYPE (retval ) == IS_LONG ) {
788
776
zend_long retval_long = Z_LVAL (retval );
@@ -795,8 +783,9 @@ static int curl_ssh_hostkeyfunction(void *clientp, int keytype, const char *key,
795
783
zend_throw_error (NULL , "The CURLOPT_SSH_HOSTKEYFUNCTION callback must return either CURLKHMATCH_OK or CURLKHMATCH_MISMATCH" );
796
784
}
797
785
}
798
- zval_ptr_dtor (& argv [0 ]);
799
- zval_ptr_dtor (& argv [2 ]);
786
+
787
+ zval_ptr_dtor (& args [0 ]);
788
+ zval_ptr_dtor (& args [2 ]);
800
789
return rval ;
801
790
}
802
791
#endif
@@ -1048,7 +1037,7 @@ void init_curl_handle(php_curl *ch)
1048
1037
ch -> handlers .xferinfo = NULL ;
1049
1038
ch -> handlers .fnmatch = NULL ;
1050
1039
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1051
- ch -> handlers .sshhostkey = NULL ;
1040
+ ch -> handlers .sshhostkey = empty_fcall_info_cache ;
1052
1041
#endif
1053
1042
ch -> clone = emalloc (sizeof (uint32_t ));
1054
1043
* ch -> clone = 1 ;
@@ -1232,7 +1221,7 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
1232
1221
_php_copy_callback (ch , & ch -> handlers .xferinfo , source -> handlers .xferinfo , CURLOPT_XFERINFODATA );
1233
1222
_php_copy_callback (ch , & ch -> handlers .fnmatch , source -> handlers .fnmatch , CURLOPT_FNMATCH_DATA );
1234
1223
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1235
- _php_copy_callback (ch , & ch -> handlers .sshhostkey , source -> handlers .sshhostkey , CURLOPT_SSH_HOSTKEYDATA );
1224
+ php_curl_copy_fcc_with_option (ch , CURLOPT_SSH_HOSTKEYDATA , & ch -> handlers .sshhostkey , & source -> handlers .sshhostkey );
1236
1225
#endif
1237
1226
1238
1227
ZVAL_COPY (& ch -> private_data , & source -> private_data );
@@ -2109,17 +2098,17 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
2109
2098
}
2110
2099
2111
2100
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2112
- case CURLOPT_SSH_HOSTKEYFUNCTION :
2101
+ case CURLOPT_SSH_HOSTKEYFUNCTION : {
2102
+ /* Check value is actually a callable and set it */
2103
+ const char option_name [] = "CURLOPT_SSH_HOSTKEYFUNCTION" ;
2104
+ bool result = php_curl_set_callable_handler (& ch -> handlers .sshhostkey , zvalue , is_array_config , option_name );
2105
+ if (!result ) {
2106
+ return FAILURE ;
2107
+ }
2113
2108
curl_easy_setopt (ch -> cp , CURLOPT_SSH_HOSTKEYFUNCTION , curl_ssh_hostkeyfunction );
2114
2109
curl_easy_setopt (ch -> cp , CURLOPT_SSH_HOSTKEYDATA , ch );
2115
- if (ch -> handlers .sshhostkey == NULL ) {
2116
- ch -> handlers .sshhostkey = ecalloc (1 , sizeof (php_curl_callback ));
2117
- } else if (!Z_ISUNDEF (ch -> handlers .sshhostkey -> func_name )) {
2118
- zval_ptr_dtor (& ch -> handlers .sshhostkey -> func_name );
2119
- ch -> handlers .sshhostkey -> fci_cache = empty_fcall_info_cache ;
2120
- }
2121
- ZVAL_COPY (& ch -> handlers .sshhostkey -> func_name , zvalue );
2122
2110
break ;
2111
+ }
2123
2112
#endif
2124
2113
2125
2114
case CURLOPT_READFUNCTION :
@@ -2803,7 +2792,9 @@ static void curl_free_obj(zend_object *object)
2803
2792
_php_curl_free_callback (ch -> handlers .xferinfo );
2804
2793
_php_curl_free_callback (ch -> handlers .fnmatch );
2805
2794
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2806
- _php_curl_free_callback (ch -> handlers .sshhostkey );
2795
+ if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
2796
+ zend_fcc_dtor (& ch -> handlers .sshhostkey );
2797
+ }
2807
2798
#endif
2808
2799
2809
2800
zval_ptr_dtor (& ch -> postfields );
@@ -2884,10 +2875,8 @@ static void _php_curl_reset_handlers(php_curl *ch)
2884
2875
}
2885
2876
2886
2877
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2887
- if (ch -> handlers .sshhostkey ) {
2888
- zval_ptr_dtor (& ch -> handlers .sshhostkey -> func_name );
2889
- efree (ch -> handlers .sshhostkey );
2890
- ch -> handlers .sshhostkey = NULL ;
2878
+ if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
2879
+ zend_fcc_dtor (& ch -> handlers .sshhostkey );
2891
2880
}
2892
2881
#endif
2893
2882
}
0 commit comments