diff --git a/UPGRADING b/UPGRADING index ae0e3afc97ad..d332f75a4e61 100644 --- a/UPGRADING +++ b/UPGRADING @@ -19,6 +19,10 @@ PHP 8.6 UPGRADE NOTES 1. Backward Incompatible Changes ======================================== +- COM + . It is no longer possible to clone variant objects, this is because + the cloning behaviour was ill defined. + - DOM: . Properties previously documented as @readonly (e.g. DOMNode::$nodeType, DOMDocument::$xmlEncoding, DOMEntity::$actualEncoding, ::$encoding, diff --git a/ext/com_dotnet/com_com.c b/ext/com_dotnet/com_com.c index a0c8a955e0c5..63fc8f6563b2 100644 --- a/ext/com_dotnet/com_com.c +++ b/ext/com_dotnet/com_com.c @@ -17,8 +17,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" #include "Zend/zend_exceptions.h" diff --git a/ext/com_dotnet/com_dotnet.c b/ext/com_dotnet/com_dotnet.c index 78f420ff5591..d96aa0f1b120 100644 --- a/ext/com_dotnet/com_dotnet.c +++ b/ext/com_dotnet/com_dotnet.c @@ -16,11 +16,9 @@ #include #endif -#include "php.h" +# include "php.h" #ifdef HAVE_MSCOREE_H -# include "php_ini.h" -# include "ext/standard/info.h" # include "php_com_dotnet.h" # include "php_com_dotnet_internal.h" # include "Zend/zend_exceptions.h" diff --git a/ext/com_dotnet/com_handlers.c b/ext/com_dotnet/com_handlers.c index 81c42da34972..e4b187b3c98d 100644 --- a/ext/com_dotnet/com_handlers.c +++ b/ext/com_dotnet/com_handlers.c @@ -17,8 +17,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" #include "Zend/zend_exceptions.h" @@ -511,7 +509,7 @@ zend_object_handlers php_com_object_handlers = { 0, php_com_object_free_storage, zend_objects_destroy_object, - php_com_object_clone, + NULL, /* clone */ NULL, /* clone_with */ com_property_read, com_property_write, @@ -589,30 +587,6 @@ void php_com_object_free_storage(zend_object *object) zend_object_std_dtor(object); } -zend_object* php_com_object_clone(zend_object *object) -{ - php_com_dotnet_object *cloneobj, *origobject; - - origobject = (php_com_dotnet_object*) object; - cloneobj = (php_com_dotnet_object*)emalloc(sizeof(php_com_dotnet_object)); - - memcpy(cloneobj, origobject, sizeof(*cloneobj)); - - /* VariantCopy will perform VariantClear; we don't want to clobber - * the IDispatch that we memcpy'd, so we init a new variant in the - * clone structure */ - VariantInit(&cloneobj->v); - /* We use the Indirection-following version of the API since we - * want to clone as much as possible */ - VariantCopyInd(&cloneobj->v, &origobject->v); - - if (cloneobj->typeinfo) { - ITypeInfo_AddRef(cloneobj->typeinfo); - } - - return (zend_object*)cloneobj; -} - zend_object* php_com_object_new(zend_class_entry *ce) { php_com_dotnet_object *obj; diff --git a/ext/com_dotnet/com_iterator.c b/ext/com_dotnet/com_iterator.c index 796a31ac9be5..ee8f65c12c1a 100644 --- a/ext/com_dotnet/com_iterator.c +++ b/ext/com_dotnet/com_iterator.c @@ -17,8 +17,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" #include "Zend/zend_exceptions.h" diff --git a/ext/com_dotnet/com_misc.c b/ext/com_dotnet/com_misc.c index 47c670cd3588..2cca9f11ca3c 100644 --- a/ext/com_dotnet/com_misc.c +++ b/ext/com_dotnet/com_misc.c @@ -17,8 +17,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" #include "Zend/zend_exceptions.h" diff --git a/ext/com_dotnet/com_olechar.c b/ext/com_dotnet/com_olechar.c index 6270db6580f8..c4c7ca7a6a71 100644 --- a/ext/com_dotnet/com_olechar.c +++ b/ext/com_dotnet/com_olechar.c @@ -18,8 +18,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" diff --git a/ext/com_dotnet/com_persist.c b/ext/com_dotnet/com_persist.c index 5559567cbab3..916a8b05f139 100644 --- a/ext/com_dotnet/com_persist.c +++ b/ext/com_dotnet/com_persist.c @@ -25,8 +25,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" #include "Zend/zend_exceptions.h" diff --git a/ext/com_dotnet/com_saproxy.c b/ext/com_dotnet/com_saproxy.c index 0317c329589e..7cfdef4885f6 100644 --- a/ext/com_dotnet/com_saproxy.c +++ b/ext/com_dotnet/com_saproxy.c @@ -24,8 +24,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" #include "Zend/zend_exceptions.h" diff --git a/ext/com_dotnet/com_typeinfo.c b/ext/com_dotnet/com_typeinfo.c index ca20ed004d87..f80075c050ac 100644 --- a/ext/com_dotnet/com_typeinfo.c +++ b/ext/com_dotnet/com_typeinfo.c @@ -18,8 +18,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" diff --git a/ext/com_dotnet/com_variant.c b/ext/com_dotnet/com_variant.c index da3ccc64ffb3..82f17d12d9b5 100644 --- a/ext/com_dotnet/com_variant.c +++ b/ext/com_dotnet/com_variant.c @@ -17,8 +17,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" diff --git a/ext/com_dotnet/com_wrapper.c b/ext/com_dotnet/com_wrapper.c index c2297d18e58c..175a2de33074 100644 --- a/ext/com_dotnet/com_wrapper.c +++ b/ext/com_dotnet/com_wrapper.c @@ -20,8 +20,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "php_com_dotnet.h" #include "php_com_dotnet_internal.h" diff --git a/ext/com_dotnet/php_com_dotnet_internal.h b/ext/com_dotnet/php_com_dotnet_internal.h index 5aef37659c44..c7e065c24872 100644 --- a/ext/com_dotnet/php_com_dotnet_internal.h +++ b/ext/com_dotnet/php_com_dotnet_internal.h @@ -66,7 +66,6 @@ extern zend_class_entry *php_com_variant_class_entry, *php_com_exception_class_e /* com_handlers.c */ zend_object* php_com_object_new(zend_class_entry *ce); -zend_object* php_com_object_clone(zend_object *object); void php_com_object_free_storage(zend_object *object); extern zend_object_handlers php_com_object_handlers; void php_com_object_enable_event_sink(php_com_dotnet_object *obj, bool enable); @@ -115,9 +114,11 @@ PHP_COM_DOTNET_API zend_result php_com_zval_from_variant(zval *z, VARIANT *v, in PHP_COM_DOTNET_API zend_result php_com_copy_variant(VARIANT *dst, VARIANT *src); /* com_dotnet.c */ +#ifdef HAVE_MSCOREE_H PHP_METHOD(dotnet, __construct); void php_com_dotnet_rshutdown(void); void php_com_dotnet_mshutdown(void); +#endif /* com_misc.c */ void php_com_throw_exception(HRESULT code, char *message); diff --git a/ext/com_dotnet/tests/bug77177.phpt b/ext/com_dotnet/tests/bug77177.phpt index 3395f4ed810d..cba12980ad97 100644 --- a/ext/com_dotnet/tests/bug77177.phpt +++ b/ext/com_dotnet/tests/bug77177.phpt @@ -2,16 +2,11 @@ Bug #77177 (Serializing or unserializing COM objects crashes) --EXTENSIONS-- com_dotnet ---SKIPIF-- - --FILE-- ---EXPECTF-- +--EXPECT-- Exception: Serialization of 'com' is not allowed -Exception: Serialization of 'dotnet' is not allowed Exception: Serialization of 'variant' is not allowed Exception: Unserialization of 'com' is not allowed -Exception: Unserialization of 'dotnet' is not allowed Exception: Unserialization of 'variant' is not allowed Exception: Unserialization of 'com' is not allowed -Exception: Unserialization of 'dotnet' is not allowed Exception: Unserialization of 'variant' is not allowed diff --git a/ext/com_dotnet/tests/bug77177_dotnet.phpt b/ext/com_dotnet/tests/bug77177_dotnet.phpt new file mode 100644 index 000000000000..d80c180ae772 --- /dev/null +++ b/ext/com_dotnet/tests/bug77177_dotnet.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #77177 (Serializing or unserializing COM objects crashes, dotnet class) +--EXTENSIONS-- +com_dotnet +--SKIPIF-- + +--FILE-- +getMessage()}\n"; +} + +try { + unserialize('C:6:"dotnet":0:{}'); +} catch (Exception $ex) { + echo "Exception: {$ex->getMessage()}\n"; +} + +try { + unserialize('O:6:"dotnet":0:{}'); +} catch (Exception $ex) { + echo "Exception: {$ex->getMessage()}\n"; +} +?> +--EXPECT-- +Exception: Serialization of 'dotnet' is not allowed +Exception: Unserialization of 'dotnet' is not allowed +Exception: Unserialization of 'dotnet' is not allowed diff --git a/ext/com_dotnet/tests/sa_proxy_errors.phpt b/ext/com_dotnet/tests/sa_proxy_errors.phpt new file mode 100644 index 000000000000..99acb0c01521 --- /dev/null +++ b/ext/com_dotnet/tests/sa_proxy_errors.phpt @@ -0,0 +1,60 @@ +--TEST-- +com_safearray_proxy errors +--EXTENSIONS-- +com_dotnet +--FILE-- +hello)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + var_dump($v->hello); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + $v->hello = 'blah'; + var_dump($v); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + unset($v->hello); + var_dump($v); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + $c = clone $v; + var_dump($c); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +try { + $s = serialize($v); + var_dump($s); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +?> +--EXPECT-- +object(variant)#1 (0) { +} +bool(false) +com_exception: this variant has no properties +com_exception: this variant has no properties +Error: Cannot delete properties from a COM object +Error: Trying to clone an uncloneable object of class variant +Exception: Serialization of 'variant' is not allowed diff --git a/ext/com_dotnet/tests/variant_no_clone.phpt b/ext/com_dotnet/tests/variant_no_clone.phpt new file mode 100644 index 000000000000..93d49235ed4e --- /dev/null +++ b/ext/com_dotnet/tests/variant_no_clone.phpt @@ -0,0 +1,19 @@ +--TEST-- +Prevent cloning of Variant types as it's broken +--EXTENSIONS-- +com_dotnet +--FILE-- +getMessage(), "\n"; +} + +?> +--EXPECT-- +Error: Trying to clone an uncloneable object of class variant