From 780a9445afc58a46a6c1e4dd3c4b5a4ce7f03042 Mon Sep 17 00:00:00 2001 From: Toon Schoenmakers Date: Thu, 8 Oct 2015 11:04:54 +0200 Subject: Properly handle a Php::Exception when thrown from a serialize method --- zend/classimpl.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/zend/classimpl.cpp b/zend/classimpl.cpp index ad7dab4..30c90c9 100644 --- a/zend/classimpl.cpp +++ b/zend/classimpl.cpp @@ -1260,14 +1260,27 @@ int ClassImpl::serialize(zval *object, unsigned char **buffer, zend_uint *buf_le // get the serializable object Serializable *serializable = dynamic_cast(ObjectImpl::find(object TSRMLS_CC)->object()); - // call the serialize method on the object - auto value = serializable->serialize(); - - // allocate the buffer, and copy the data into it (the zend engine will - // (hopefully) clean up the data for us - the default serialize method does - // it like this too) - *buffer = (unsigned char*)estrndup(value.c_str(), value.size()); - *buf_len = value.size(); + // user may throw an exception in the serialize() function + try + { + // call the serialize method on the object + auto value = serializable->serialize(); + + // allocate the buffer, and copy the data into it (the zend engine will + // (hopefully) clean up the data for us - the default serialize method does + // it like this too) + *buffer = (unsigned char*)estrndup(value.c_str(), value.size()); + *buf_len = value.size(); + } + catch (Exception &exception) + { + // user threw an exception in its method + // implementation, send it to user space + process(exception TSRMLS_CC); + + // unreachable + return FAILURE; + } // done return SUCCESS; -- cgit v1.2.3