Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions ext/com_dotnet/com_dotnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
#include <config.h>
#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"
Expand Down
28 changes: 1 addition & 27 deletions ext/com_dotnet/com_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_olechar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_saproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_typeinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_variant.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion ext/com_dotnet/php_com_dotnet_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 4 additions & 12 deletions ext/com_dotnet/tests/bug77177.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
Bug #77177 (Serializing or unserializing COM objects crashes)
--EXTENSIONS--
com_dotnet
--SKIPIF--
<?php
if (!class_exists("dotnet")) die("skip mscoree not available");
?>
--FILE--
<?php
$com = new COM("WScript.Shell");
$dotnet = new DOTNET("mscorlib", "System.Collections.Stack");
$variant = new VARIANT;
foreach ([$com, $dotnet, $variant] as $object) {
foreach ([$com, $variant] as $object) {
try {
serialize($object);
} catch (Exception $ex) {
echo "Exception: {$ex->getMessage()}\n";
}
}

$strings = ['C:3:"com":0:{}', 'C:6:"dotnet":0:{}', 'C:7:"variant":0:{}'];
$strings = ['C:3:"com":0:{}', 'C:7:"variant":0:{}'];
foreach ($strings as $string) {
try {
unserialize($string);
Expand All @@ -28,7 +23,7 @@ foreach ($strings as $string) {
}
}

$strings = ['O:3:"com":0:{}', 'O:6:"dotnet":0:{}', 'O:7:"variant":0:{}'];
$strings = ['O:3:"com":0:{}', 'O:7:"variant":0:{}'];
foreach ($strings as $string) {
try {
unserialize($string);
Expand All @@ -37,13 +32,10 @@ foreach ($strings as $string) {
}
}
?>
--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
33 changes: 33 additions & 0 deletions ext/com_dotnet/tests/bug77177_dotnet.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Bug #77177 (Serializing or unserializing COM objects crashes, dotnet class)
--EXTENSIONS--
com_dotnet
--SKIPIF--
<?php
if (!class_exists("dotnet")) die("skip mscoree not available");
?>
--FILE--
<?php
$dotnet = new DOTNET("mscorlib", "System.Collections.Stack");
try {
serialize($dotnet);
} catch (Exception $ex) {
echo "Exception: {$ex->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
60 changes: 60 additions & 0 deletions ext/com_dotnet/tests/sa_proxy_errors.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--TEST--
com_safearray_proxy errors
--EXTENSIONS--
com_dotnet
--FILE--
<?php

$binding_string = ['aaa','bbb','ccc'];
$v = new VARIANT( $binding_string, VT_ARRAY );
var_dump($v);

try {
var_dump(isset($v->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
19 changes: 19 additions & 0 deletions ext/com_dotnet/tests/variant_no_clone.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Prevent cloning of Variant types as it's broken
--EXTENSIONS--
com_dotnet
--FILE--
<?php

$v = new variant("123");

try {
$v2 = clone $v;
var_dump($v2);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
Error: Trying to clone an uncloneable object of class variant