From 8b7a4d319b56220f2ef03eaa4190a55db59cde5c Mon Sep 17 00:00:00 2001 From: Toon Schoenmakers Date: Thu, 8 Oct 2015 11:38:50 +0200 Subject: 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). --- zend/classimpl.cpp | 18 ++++++++++++++++-- 1 file 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(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; -- cgit v1.2.3