Commit 4b6c465588b for php.net

commit 4b6c465588bf0aee11d7b176f61f4634c2e13467
Author: Tim Düsterhus <tim@tideways-gmbh.com>
Date:   Wed Sep 17 17:03:06 2025 +0200

    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.

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 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
 /* {{{ 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);
 }
 /* }}} */