diff options
author | Joe George <joe@zeroc.com> | 2020-07-07 16:57:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-07 16:57:51 -0400 |
commit | 6c0e7e6fcabde691e7c38a814b6171f9f4e77d09 (patch) | |
tree | aed41fdff6561e134c73da214e580be0910e6f6a /php | |
parent | Copy python dependencies to the extension directory - Close #926 (#927) (diff) | |
download | ice-6c0e7e6fcabde691e7c38a814b6171f9f4e77d09.tar.bz2 ice-6c0e7e6fcabde691e7c38a814b6171f9f4e77d09.tar.xz ice-6c0e7e6fcabde691e7c38a814b6171f9f4e77d09.zip |
Add class cycle detection during unmarshaling (#946)
Add support for detection of class cycles during unmarshaling in
languages which do no have garbage collection: C++, Swift, and Objective-C.
A `MarshalException` is thrown when a cycle is detected.
The property `Ice.AcceptClassCycles` can be set to a value greater than `0`
to change this behavior.
Diffstat (limited to 'php')
-rw-r--r-- | php/src/php5/Communicator.cpp | 8 | ||||
-rw-r--r-- | php/src/php7/Communicator.cpp | 8 | ||||
-rw-r--r-- | php/test/Ice/objects/Client.php | 17 | ||||
-rw-r--r-- | php/test/Ice/objects/Test.ice | 3 |
4 files changed, 36 insertions, 0 deletions
diff --git a/php/src/php5/Communicator.cpp b/php/src/php5/Communicator.cpp index a7d185e9ccc..41b91656238 100644 --- a/php/src/php5/Communicator.cpp +++ b/php/src/php5/Communicator.cpp @@ -1234,6 +1234,14 @@ ZEND_FUNCTION(Ice_initialize) initData.compactIdResolver = new IdResolver(TSRMLS_C); initData.valueFactoryManager = new ValueFactoryManager; + if(!initData.properties) + { + initData.properties = Ice::createProperties(); + } + + // Always accept cycles in PHP + initData.properties->setProperty("Ice.AcceptClassCycles", "1"); + CommunicatorInfoIPtr info = initializeCommunicator(return_value, seq, zvargs != 0, initData TSRMLS_CC); if(!info) { diff --git a/php/src/php7/Communicator.cpp b/php/src/php7/Communicator.cpp index 3a0f53ca70b..4143ec65a4c 100644 --- a/php/src/php7/Communicator.cpp +++ b/php/src/php7/Communicator.cpp @@ -1245,6 +1245,14 @@ ZEND_FUNCTION(Ice_initialize) initData.compactIdResolver = new IdResolver(); initData.valueFactoryManager = new ValueFactoryManager; + if(!initData.properties) + { + initData.properties = Ice::createProperties(); + } + + // Always accept cycles in PHP + initData.properties->setProperty("Ice.AcceptClassCycles", "1"); + CommunicatorInfoIPtr info = initializeCommunicator(return_value, seq, zvargs != 0, initData); if(!info) { diff --git a/php/test/Ice/objects/Client.php b/php/test/Ice/objects/Client.php index cc6e62bb838..9355713801b 100644 --- a/php/test/Ice/objects/Client.php +++ b/php/test/Ice/objects/Client.php @@ -595,6 +595,23 @@ function allTests($helper) } echo "ok\n"; + echo "testing sending class cycle..."; + $rec = new Test_Recursive(); + $rec->v = $rec; + $acceptsCycles = $initial->acceptsClassCycles(); + try + { + $initial->setCycle($rec); + test($acceptsCycles); + } + catch(Exception $ex) + { + $ule = $NS ? "Ice\\UnknownLocalException" : "Ice_UnknownLocalException"; + test($ex instanceof $ule); + test(!$acceptsCycles); + } + echo "ok\n"; + return $initial; } diff --git a/php/test/Ice/objects/Test.ice b/php/test/Ice/objects/Test.ice index 81fc72314b2..cf407b7cf90 100644 --- a/php/test/Ice/objects/Test.ice +++ b/php/test/Ice/objects/Test.ice @@ -173,6 +173,9 @@ interface Initial void setRecursive(Recursive p); bool supportsClassGraphDepthMax(); + void setCycle(Recursive r); + bool acceptsClassCycles(); + ["marshaled-result"] B getMB(); ["amd", "marshaled-result"] B getAMDMB(); |