]> granicus.if.org Git - php/commitdiff
Fix #46646 (Implement zend functions to restrict serialization or internal classes)
authorEtienne Kneuss <colder@php.net>
Mon, 22 Dec 2008 13:50:43 +0000 (13:50 +0000)
committerEtienne Kneuss <colder@php.net>
Mon, 22 Dec 2008 13:50:43 +0000 (13:50 +0000)
Zend/zend_closures.c
Zend/zend_interfaces.c
Zend/zend_interfaces.h
ext/spl/spl_directory.c

index 6c0cd2eaa5d80f3159350e47d3c6ae33e9d7f322..d22ba4fdb323684cedc153fb822030c4b1f30e2c 100644 (file)
@@ -22,6 +22,7 @@
 #include "zend.h"
 #include "zend_API.h"
 #include "zend_closures.h"
+#include "zend_interfaces.h"
 #include "zend_objects.h"
 #include "zend_objects_API.h"
 #include "zend_globals.h"
@@ -78,20 +79,6 @@ static zend_function *zend_closure_get_constructor(zval *object TSRMLS_DC) /* {{
 }
 /* }}} */
 
-static int zend_closure_serialize(zval *object, int *type, zstr *buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC) /* {{{ */
-{
-       zend_error(E_RECOVERABLE_ERROR, "Serialization of 'Closure' is not allowed");
-       return FAILURE;
-}
-/* }}} */
-
-static int zend_closure_unserialize(zval **object, zend_class_entry *ce, int type, const zstr buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC) /* {{{ */
-{
-       zend_error(E_RECOVERABLE_ERROR, "Unserialization of 'Closure' is not allowed");
-       return FAILURE;
-}
-/* }}} */
-
 static int zend_closure_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
 {
        return (Z_OBJ_HANDLE_P(o1) != Z_OBJ_HANDLE_P(o2));
@@ -247,8 +234,8 @@ void zend_register_closure_ce(TSRMLS_D) /* {{{ */
        zend_ce_closure = zend_register_internal_class(&ce TSRMLS_CC);
        zend_ce_closure->ce_flags |= ZEND_ACC_FINAL_CLASS;
        zend_ce_closure->create_object = zend_closure_new;
-       zend_ce_closure->serialize = zend_closure_serialize;
-       zend_ce_closure->unserialize = zend_closure_unserialize;
+       zend_ce_closure->serialize = zend_class_serialize_deny;
+       zend_ce_closure->unserialize = zend_class_unserialize_deny;
 
        memcpy(&closure_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        closure_handlers.get_constructor = zend_closure_get_constructor;
index 15bcdd91ebcc3e5a21bb08019f21932c08517d2c..31becb7b142ea1677131582195e02190bc26e02a 100755 (executable)
@@ -471,6 +471,19 @@ ZEND_API int zend_user_unserialize(zval **object, zend_class_entry *ce, int type
 }
 /* }}} */
 
+ZEND_API int zend_class_serialize_deny(zval *object, int *type, zstr *buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC) /* {{{ */
+{
+       zend_class_entry *ce = Z_OBJCE_P(object);
+       zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Serialization of '%s' is not allowed", ce->name);
+       return FAILURE;
+} /* }}} */
+
+ZEND_API int zend_class_unserialize_deny(zval **object, zend_class_entry *ce, int type, const zstr buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC) /* {{{ */
+{
+       zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Unserialization of '%s' is not allowed", ce->name);
+       return FAILURE;
+} /* }}} */
+
 /* {{{ zend_implement_serializable */
 static int zend_implement_serializable(zend_class_entry *interface, zend_class_entry *class_type TSRMLS_DC)
 {
index dbf5f9db3fa58bdfd3f03525bb4cc95805ddecd3..26bc971c13741a6de1b3acedf23020d65a3016d9 100755 (executable)
@@ -69,6 +69,9 @@ ZEND_API void zend_register_interfaces(TSRMLS_D);
 ZEND_API int zend_user_serialize(zval *object, int *type, zstr *buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC);
 ZEND_API int zend_user_unserialize(zval **object, zend_class_entry *ce, int type, const zstr buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC);
 
+ZEND_API int zend_class_serialize_deny(zval *object, int *type, zstr *buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC);
+ZEND_API int zend_class_unserialize_deny(zval **object, zend_class_entry *ce, int type, const zstr buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC);
+
 END_EXTERN_C()
 
 #endif /* ZEND_INTERFACES_H */
index dbe1ce682e3e3271283534c502f9a7228966afb3..5f3c1e6930c35b40feb072dafe105eef53ac920e 100755 (executable)
@@ -2753,6 +2753,8 @@ PHP_MINIT_FUNCTION(spl_directory)
        spl_filesystem_object_handlers.clone_obj      = spl_filesystem_object_clone;
        spl_filesystem_object_handlers.cast_object    = spl_filesystem_object_cast;
        spl_filesystem_object_handlers.get_debug_info = spl_filesystem_object_get_debug_info;
+       spl_ce_SplFileInfo->serialize = zend_class_serialize_deny;
+       spl_ce_SplFileInfo->unserialize = zend_class_unserialize_deny;
 
        REGISTER_SPL_SUB_CLASS_EX(DirectoryIterator, SplFileInfo, spl_filesystem_object_new, spl_DirectoryIterator_functions);
        zend_class_implements(spl_ce_DirectoryIterator TSRMLS_CC, 1, zend_ce_iterator);