summaryrefslogtreecommitdiff
path: root/Zend/zend_generators.c
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2012-08-20 16:01:16 +0200
committerNikita Popov <nikic@php.net>2012-08-20 16:01:16 +0200
commitf45a0f31c8354947c0e2b9ea44a63fc0a2c23a01 (patch)
tree5f96fef17e0aba78b4f2b40cd2cedd54af680b98 /Zend/zend_generators.c
parent1823b16fa15894f72fc01724766289dbecf5a62a (diff)
downloadphp-git-f45a0f31c8354947c0e2b9ea44a63fc0a2c23a01.tar.gz
Disallow serialization and unserialization
Diffstat (limited to 'Zend/zend_generators.c')
-rw-r--r--Zend/zend_generators.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 41c6dfcd94..b4d8932b6b 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -590,6 +590,23 @@ ZEND_METHOD(Generator, send)
}
}
+
+/* {{{ proto void Generator::__wakeup
+ * Throws an Exception as generators can't be serialized */
+ZEND_METHOD(Generator, __wakeup)
+{
+ /* Just specifying the zend_class_unserialize_deny handler is not enough,
+ * because it is only invoked for C unserialization. For O the error has
+ * to be thrown in __wakeup. */
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ zend_throw_exception(NULL, "Unserialization of 'Generator' is not allowed", 0 TSRMLS_CC);
+}
+/* }}} */
+
/* get_iterator implementation */
typedef struct _zend_generator_iterator {
@@ -712,12 +729,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_generator_send, 0, 0, 1)
ZEND_END_ARG_INFO()
static const zend_function_entry generator_functions[] = {
- ZEND_ME(Generator, rewind, arginfo_generator_void, ZEND_ACC_PUBLIC)
- ZEND_ME(Generator, valid, arginfo_generator_void, ZEND_ACC_PUBLIC)
- ZEND_ME(Generator, current, arginfo_generator_void, ZEND_ACC_PUBLIC)
- ZEND_ME(Generator, key, arginfo_generator_void, ZEND_ACC_PUBLIC)
- ZEND_ME(Generator, next, arginfo_generator_void, ZEND_ACC_PUBLIC)
- ZEND_ME(Generator, send, arginfo_generator_send, ZEND_ACC_PUBLIC)
+ ZEND_ME(Generator, rewind, arginfo_generator_void, ZEND_ACC_PUBLIC)
+ ZEND_ME(Generator, valid, arginfo_generator_void, ZEND_ACC_PUBLIC)
+ ZEND_ME(Generator, current, arginfo_generator_void, ZEND_ACC_PUBLIC)
+ ZEND_ME(Generator, key, arginfo_generator_void, ZEND_ACC_PUBLIC)
+ ZEND_ME(Generator, next, arginfo_generator_void, ZEND_ACC_PUBLIC)
+ ZEND_ME(Generator, send, arginfo_generator_send, ZEND_ACC_PUBLIC)
+ ZEND_ME(Generator, __wakeup, arginfo_generator_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
@@ -729,6 +747,8 @@ void zend_register_generator_ce(TSRMLS_D) /* {{{ */
zend_ce_generator = zend_register_internal_class(&ce TSRMLS_CC);
zend_ce_generator->ce_flags |= ZEND_ACC_FINAL_CLASS;
zend_ce_generator->create_object = zend_generator_create;
+ zend_ce_generator->serialize = zend_class_serialize_deny;
+ zend_ce_generator->unserialize = zend_class_unserialize_deny;
/* get_iterator has to be assigned *after* implementing the inferface */
zend_class_implements(zend_ce_generator TSRMLS_CC, 1, zend_ce_iterator);