Skip to content

Commit 79871b4

Browse files
committed
ext/com: remove ability to clone Variants
As it is seriously broken
1 parent 11eab53 commit 79871b4

4 files changed

Lines changed: 25 additions & 26 deletions

File tree

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP 8.6 UPGRADE NOTES
1919
1. Backward Incompatible Changes
2020
========================================
2121

22+
- COM
23+
. It is no longer possible to clone variant objects, this is because
24+
the cloning behaviour was ill defined.
25+
2226
- DOM:
2327
. Properties previously documented as @readonly (e.g. DOMNode::$nodeType,
2428
DOMDocument::$xmlEncoding, DOMEntity::$actualEncoding, ::$encoding,

ext/com_dotnet/com_handlers.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ zend_object_handlers php_com_object_handlers = {
509509
0,
510510
php_com_object_free_storage,
511511
zend_objects_destroy_object,
512-
php_com_object_clone,
512+
NULL, /* clone */
513513
NULL, /* clone_with */
514514
com_property_read,
515515
com_property_write,
@@ -587,30 +587,6 @@ void php_com_object_free_storage(zend_object *object)
587587
zend_object_std_dtor(object);
588588
}
589589

590-
zend_object* php_com_object_clone(zend_object *object)
591-
{
592-
php_com_dotnet_object *cloneobj, *origobject;
593-
594-
origobject = (php_com_dotnet_object*) object;
595-
cloneobj = (php_com_dotnet_object*)emalloc(sizeof(php_com_dotnet_object));
596-
597-
memcpy(cloneobj, origobject, sizeof(*cloneobj));
598-
599-
/* VariantCopy will perform VariantClear; we don't want to clobber
600-
* the IDispatch that we memcpy'd, so we init a new variant in the
601-
* clone structure */
602-
VariantInit(&cloneobj->v);
603-
/* We use the Indirection-following version of the API since we
604-
* want to clone as much as possible */
605-
VariantCopyInd(&cloneobj->v, &origobject->v);
606-
607-
if (cloneobj->typeinfo) {
608-
ITypeInfo_AddRef(cloneobj->typeinfo);
609-
}
610-
611-
return (zend_object*)cloneobj;
612-
}
613-
614590
zend_object* php_com_object_new(zend_class_entry *ce)
615591
{
616592
php_com_dotnet_object *obj;

ext/com_dotnet/php_com_dotnet_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ extern zend_class_entry *php_com_variant_class_entry, *php_com_exception_class_e
6666

6767
/* com_handlers.c */
6868
zend_object* php_com_object_new(zend_class_entry *ce);
69-
zend_object* php_com_object_clone(zend_object *object);
7069
void php_com_object_free_storage(zend_object *object);
7170
extern zend_object_handlers php_com_object_handlers;
7271
void php_com_object_enable_event_sink(php_com_dotnet_object *obj, bool enable);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Prevent cloning of Variant types as it's broken
3+
--EXTENSIONS--
4+
com_dotnet
5+
6+
--FILE--
7+
<?php
8+
9+
$v = new variant("123");
10+
11+
try {
12+
$v2 = clone $v;
13+
var_dump($v2);
14+
} catch (Throwable $e) {
15+
echo $e::class, ': ', $e->getMessage(), "\n";
16+
}
17+
18+
?>
19+
--EXPECT--
20+
Error: Trying to clone an uncloneable object of class variant

0 commit comments

Comments
 (0)