summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Schoenmakers <toon.schoenmakers@copernica.com>2015-10-08 11:38:50 +0200
committerToon Schoenmakers <toon.schoenmakers@copernica.com>2015-10-08 11:38:50 +0200
commit8b7a4d319b56220f2ef03eaa4190a55db59cde5c (patch)
tree5638a78b3358680ec7775df62fdc66e9288d1d20
parent780a9445afc58a46a6c1e4dd3c4b5a4ce7f03042 (diff)
Handle exceptions thrown from unserialize similar to normal php
Most of this code was taken from ext/standard/vars.c:948, the error message isn't the same, but that's just a small detail. Funny enough you can actually make unserialize throw if you make this code handling the same as serialize, but as the php documentation says that unserialize doesn't throw we just handle it like this (the way we should).
-rw-r--r--zend/classimpl.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/zend/classimpl.cpp b/zend/classimpl.cpp
index 30c90c9..4224e6c 100644
--- a/zend/classimpl.cpp
+++ b/zend/classimpl.cpp
@@ -1303,8 +1303,22 @@ int ClassImpl::unserialize(zval **object, zend_class_entry *entry, const unsigne
// turn this into a serializale
Serializable *serializable = dynamic_cast<Serializable*>(ObjectImpl::find(*object TSRMLS_CC)->object());
- // call the unserialize method on it
- serializable->unserialize((const char *)buffer, buf_len);
+ // user may throw an exception in the serialize() function
+ try
+ {
+ // call the unserialize method on it
+ serializable->unserialize((const char *)buffer, buf_len);
+ }
+ catch (Exception &exception)
+ {
+ // user threw an exception in its method
+ // implementation, send it to user space
+ //process(exception TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error while unserializing");
+
+ // unreachable
+ return FAILURE;
+ }
// done
return SUCCESS;