From 4b6c465588bf0aee11d7b176f61f4634c2e13467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 17 Sep 2025 17:03:06 +0200 Subject: [PATCH] Implement curl_copy_handle in terms of object cloning (#19841) This prevents the implementations from going out of sync, causing bugs like php/php-src#19813. --- ext/curl/interface.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/ext/curl/interface.c b/ext/curl/interface.c index e9e9cd5e409..4bd6cd64fa6 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -1544,37 +1544,23 @@ out_mime: /* {{{ Copy a cURL handle along with all of it's preferences */ PHP_FUNCTION(curl_copy_handle) { - php_curl *ch; - CURL *cp; zval *zid; - php_curl *dupch; - zval *postfields; ZEND_PARSE_PARAMETERS_START(1,1) Z_PARAM_OBJECT_OF_CLASS(zid, curl_ce) ZEND_PARSE_PARAMETERS_END(); - ch = Z_CURL_P(zid); - - cp = curl_easy_duphandle(ch->cp); - if (!cp) { + zend_object *new_object = Z_OBJ_P(zid)->handlers->clone_obj(Z_OBJ_P(zid)); + if (EG(exception)) { + if (new_object != NULL) { + OBJ_RELEASE(new_object); + } + zend_clear_exception(); php_error_docref(NULL, E_WARNING, "Cannot duplicate cURL handle"); RETURN_FALSE; } - dupch = init_curl_handle_into_zval(return_value); - dupch->cp = cp; - - _php_setup_easy_copy_handlers(dupch, ch); - - postfields = &ch->postfields; - if (Z_TYPE_P(postfields) != IS_UNDEF) { - if (build_mime_structure_from_hash(dupch, postfields) == FAILURE) { - zval_ptr_dtor(return_value); - php_error_docref(NULL, E_WARNING, "Cannot rebuild mime structure"); - RETURN_FALSE; - } - } + RETURN_OBJ(new_object); } /* }}} */