From af58f4ec9ec1e0fa47ce4205b380ef58f5ef1bcf Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Thu, 11 Dec 2014 22:28:01 +0100 Subject: [PATCH] Catch serialization of V8Function instances --- tests/serialize_002.phpt | 58 ++++++++++++++++++++++++++++++++++++++++ v8js.cc | 22 +++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/serialize_002.phpt diff --git a/tests/serialize_002.phpt b/tests/serialize_002.phpt new file mode 100644 index 0000000..9e58c65 --- /dev/null +++ b/tests/serialize_002.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test serialize(V8Function) : __sleep and __wakeup throw +--SKIPIF-- + +--FILE-- +executeString('(function() { })'); + +var_dump($obj); + +try { + $stored = serialize($obj); +} +catch(\V8JsException $e) { + var_dump(get_class($e)); + var_dump($e->getMessage()); +} + +$stored = 'O:10:"V8Function":0:{}'; + +try { + $obj2 = unserialize($stored); +} +catch(\V8JsException $e) { + var_dump(get_class($e)); + var_dump($e->getMessage()); +} + +var_dump(isset($obj2)); + +$stored = 'O:10:"V8Function":1:{s:3:"foo";i:23;}'; + +try { + $obj = unserialize($stored); +} +catch(\V8JsException $e) { + var_dump(get_class($e)); + var_dump($e->getMessage()); +} + +var_dump(isset($obj3)); + +?> +===EOF=== +--EXPECT-- +object(V8Function)#2 (0) { +} +string(13) "V8JsException" +string(56) "You cannot serialize or unserialize V8Function instances" +string(13) "V8JsException" +string(56) "You cannot serialize or unserialize V8Function instances" +bool(false) +string(13) "V8JsException" +string(56) "You cannot serialize or unserialize V8Function instances" +bool(false) +===EOF=== diff --git a/v8js.cc b/v8js.cc index e86a50e..e10cce4 100644 --- a/v8js.cc +++ b/v8js.cc @@ -649,6 +649,26 @@ PHP_METHOD(V8Function,__construct) } /* }}} */ +/* {{{ proto V8Function::__sleep() + */ +PHP_METHOD(V8Function, __sleep) +{ + zend_throw_exception(php_ce_v8js_exception, + "You cannot serialize or unserialize V8Function instances", 0 TSRMLS_CC); + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto V8Function::__wakeup() + */ +PHP_METHOD(V8Function, __wakeup) +{ + zend_throw_exception(php_ce_v8js_exception, + "You cannot serialize or unserialize V8Function instances", 0 TSRMLS_CC); + RETURN_FALSE; +} +/* }}} */ + void php_v8js_create_v8(zval *res, v8::Handle value, int flags, v8::Isolate *isolate TSRMLS_DC) /* {{{ */ { php_v8js_ctx *ctx = (php_v8js_ctx *) isolate->GetData(0); @@ -1954,6 +1974,8 @@ static const zend_function_entry v8_object_methods[] = { /* {{{ */ static const zend_function_entry v8_function_methods[] = { /* {{{ */ PHP_ME(V8Function, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(V8Function, __sleep, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + PHP_ME(V8Function, __wakeup, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) {NULL, NULL, NULL} }; /* }}} */