@@ -501,8 +501,8 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n)
501
501
}
502
502
503
503
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
504
- if (curl -> handlers .sshhostkey ) {
505
- zend_get_gc_buffer_add_zval (gc_buffer , & curl -> handlers .sshhostkey -> func_name );
504
+ if (ZEND_FCC_INITIALIZED ( curl -> handlers .sshhostkey ) ) {
505
+ zend_get_gc_buffer_add_fcc (gc_buffer , & curl -> handlers .sshhostkey );
506
506
}
507
507
#endif
508
508
@@ -751,39 +751,27 @@ static size_t curl_xferinfo(void *clientp, curl_off_t dltotal, curl_off_t dlnow,
751
751
static int curl_ssh_hostkeyfunction (void * clientp , int keytype , const char * key , size_t keylen )
752
752
{
753
753
php_curl * ch = (php_curl * )clientp ;
754
- php_curl_callback * t = ch -> handlers .sshhostkey ;
755
754
int rval = CURLKHMATCH_MISMATCH ; /* cancel connection in case of an exception */
756
755
757
756
#if PHP_CURL_DEBUG
758
757
fprintf (stderr , "curl_ssh_hostkeyfunction() called\n" );
759
758
fprintf (stderr , "clientp = %x, keytype = %d, key = %s, keylen = %zu\n" , clientp , keytype , key , keylen );
760
759
#endif
761
760
762
- zval argv [4 ];
761
+ zval args [4 ];
763
762
zval retval ;
764
- zend_result error ;
765
- zend_fcall_info fci ;
766
763
767
764
GC_ADDREF (& ch -> std );
768
- ZVAL_OBJ (& argv [0 ], & ch -> std );
769
- ZVAL_LONG (& argv [1 ], keytype );
770
- ZVAL_STRINGL (& argv [2 ], key , keylen );
771
- ZVAL_LONG (& argv [3 ], keylen );
765
+ ZVAL_OBJ (& args [0 ], & ch -> std );
766
+ ZVAL_LONG (& args [1 ], keytype );
767
+ ZVAL_STRINGL (& args [2 ], key , keylen );
768
+ ZVAL_LONG (& args [3 ], keylen );
772
769
773
- fci .size = sizeof (fci );
774
- ZVAL_COPY_VALUE (& fci .function_name , & t -> func_name );
775
- fci .object = NULL ;
776
- fci .retval = & retval ;
777
- fci .param_count = 4 ;
778
- fci .params = argv ;
779
- fci .named_params = NULL ;
770
+ ch -> in_callback = true;
771
+ zend_call_known_fcc (& ch -> handlers .sshhostkey , & retval , /* param_count */ 4 , args , /* named_params */ NULL );
772
+ ch -> in_callback = false;
780
773
781
- ch -> in_callback = 1 ;
782
- error = zend_call_function (& fci , & t -> fci_cache );
783
- ch -> in_callback = 0 ;
784
- if (error == FAILURE ) {
785
- php_error_docref (NULL , E_WARNING , "Cannot call the CURLOPT_SSH_HOSTKEYFUNCTION" );
786
- } else if (!Z_ISUNDEF (retval )) {
774
+ if (!Z_ISUNDEF (retval )) {
787
775
_php_curl_verify_handlers (ch , /* reporterror */ true);
788
776
if (Z_TYPE (retval ) == IS_LONG ) {
789
777
zend_long retval_long = Z_LVAL (retval );
@@ -796,8 +784,9 @@ static int curl_ssh_hostkeyfunction(void *clientp, int keytype, const char *key,
796
784
zend_throw_error (NULL , "The CURLOPT_SSH_HOSTKEYFUNCTION callback must return either CURLKHMATCH_OK or CURLKHMATCH_MISMATCH" );
797
785
}
798
786
}
799
- zval_ptr_dtor (& argv [0 ]);
800
- zval_ptr_dtor (& argv [2 ]);
787
+
788
+ zval_ptr_dtor (& args [0 ]);
789
+ zval_ptr_dtor (& args [2 ]);
801
790
return rval ;
802
791
}
803
792
#endif
@@ -1111,7 +1100,7 @@ void init_curl_handle(php_curl *ch)
1111
1100
ch -> handlers .xferinfo = NULL ;
1112
1101
ch -> handlers .fnmatch = NULL ;
1113
1102
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1114
- ch -> handlers .sshhostkey = NULL ;
1103
+ ch -> handlers .sshhostkey = empty_fcall_info_cache ;
1115
1104
#endif
1116
1105
ch -> clone = emalloc (sizeof (uint32_t ));
1117
1106
* ch -> clone = 1 ;
@@ -1295,7 +1284,7 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
1295
1284
_php_copy_callback (ch , & ch -> handlers .xferinfo , source -> handlers .xferinfo , CURLOPT_XFERINFODATA );
1296
1285
_php_copy_callback (ch , & ch -> handlers .fnmatch , source -> handlers .fnmatch , CURLOPT_FNMATCH_DATA );
1297
1286
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
1298
- _php_copy_callback (ch , & ch -> handlers .sshhostkey , source -> handlers .sshhostkey , CURLOPT_SSH_HOSTKEYDATA );
1287
+ php_curl_copy_fcc_with_option (ch , CURLOPT_SSH_HOSTKEYDATA , & ch -> handlers .sshhostkey , & source -> handlers .sshhostkey );
1299
1288
#endif
1300
1289
1301
1290
ZVAL_COPY (& ch -> private_data , & source -> private_data );
@@ -2172,17 +2161,17 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
2172
2161
}
2173
2162
2174
2163
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2175
- case CURLOPT_SSH_HOSTKEYFUNCTION :
2164
+ case CURLOPT_SSH_HOSTKEYFUNCTION : {
2165
+ /* Check value is actually a callable and set it */
2166
+ const char option_name [] = "CURLOPT_SSH_HOSTKEYFUNCTION" ;
2167
+ bool result = php_curl_set_callable_handler (& ch -> handlers .sshhostkey , zvalue , is_array_config , option_name );
2168
+ if (!result ) {
2169
+ return FAILURE ;
2170
+ }
2176
2171
curl_easy_setopt (ch -> cp , CURLOPT_SSH_HOSTKEYFUNCTION , curl_ssh_hostkeyfunction );
2177
2172
curl_easy_setopt (ch -> cp , CURLOPT_SSH_HOSTKEYDATA , ch );
2178
- if (ch -> handlers .sshhostkey == NULL ) {
2179
- ch -> handlers .sshhostkey = ecalloc (1 , sizeof (php_curl_callback ));
2180
- } else if (!Z_ISUNDEF (ch -> handlers .sshhostkey -> func_name )) {
2181
- zval_ptr_dtor (& ch -> handlers .sshhostkey -> func_name );
2182
- ch -> handlers .sshhostkey -> fci_cache = empty_fcall_info_cache ;
2183
- }
2184
- ZVAL_COPY (& ch -> handlers .sshhostkey -> func_name , zvalue );
2185
2173
break ;
2174
+ }
2186
2175
#endif
2187
2176
2188
2177
case CURLOPT_READFUNCTION :
@@ -2866,7 +2855,9 @@ static void curl_free_obj(zend_object *object)
2866
2855
_php_curl_free_callback (ch -> handlers .xferinfo );
2867
2856
_php_curl_free_callback (ch -> handlers .fnmatch );
2868
2857
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2869
- _php_curl_free_callback (ch -> handlers .sshhostkey );
2858
+ if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
2859
+ zend_fcc_dtor (& ch -> handlers .sshhostkey );
2860
+ }
2870
2861
#endif
2871
2862
2872
2863
zval_ptr_dtor (& ch -> postfields );
@@ -2947,10 +2938,8 @@ static void _php_curl_reset_handlers(php_curl *ch)
2947
2938
}
2948
2939
2949
2940
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.84.0 */
2950
- if (ch -> handlers .sshhostkey ) {
2951
- zval_ptr_dtor (& ch -> handlers .sshhostkey -> func_name );
2952
- efree (ch -> handlers .sshhostkey );
2953
- ch -> handlers .sshhostkey = NULL ;
2941
+ if (ZEND_FCC_INITIALIZED (ch -> handlers .sshhostkey )) {
2942
+ zend_fcc_dtor (& ch -> handlers .sshhostkey );
2954
2943
}
2955
2944
#endif
2956
2945
}
0 commit comments