From: Gabriel Caruso Date: Sun, 26 Apr 2020 02:31:47 +0000 (+0200) Subject: Check `__set_state` structure X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34c460f32975adbe8f0f0a166ce5fbc2e1dabb4e;p=php Check `__set_state` structure Fix Bug #79521. Closes GH-5462. --- diff --git a/NEWS b/NEWS index 4cc5691d9e..a6e2915ab6 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,7 @@ PHP NEWS . Fixed bug #36365 (scandir duplicates file name at every 65535th file). (cmb) . Use SSE2 instructions do locale independent strtolower. (Laruence) + . Fixed bug #79521 (Check __set_state structure). (carusogabriel) - BZ2: . Fixed bug #71263 (fread() does not report bzip2.decompress errors). (cmb) diff --git a/Zend/tests/magic_methods_set_state.phpt b/Zend/tests/magic_methods_set_state.phpt new file mode 100644 index 0000000000..389798e542 --- /dev/null +++ b/Zend/tests/magic_methods_set_state.phpt @@ -0,0 +1,14 @@ +--TEST-- +Testing __set_state() declaration with wrong modifier +--FILE-- + +--EXPECTF-- +Warning: The magic method Foo::__set_state() must be static in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 7c84456a6f..0923aa7141 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6170,6 +6170,8 @@ zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_check_magic_method_attr(fn_flags, ce, "__serialize", 0); } else if (zend_string_equals_literal(lcname, "__unserialize")) { zend_check_magic_method_attr(fn_flags, ce, "__unserialize", 0); + } else if (zend_string_equals_literal(lcname, "__set_state")) { + zend_check_magic_method_attr(fn_flags, ce, "__set_state", 1); } return lcname; diff --git a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt index 70038c31a0..e5e967e28e 100644 --- a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt @@ -52,7 +52,7 @@ class TestClass public function __wakeup() {} - public function __set_state() {} + public static function __set_state() {} public function __autoload() {} } @@ -143,7 +143,7 @@ Modifiers for method TestClass::__wakeup(): Modifiers for method TestClass::__set_state(): -0x00000001 +0x00000011 Modifiers for method TestClass::__autoload(): @@ -207,7 +207,7 @@ Modifiers for method TestClass::__wakeup(): Modifiers for method TestClass::__set_state(): -0x00000001 +0x00000011 Modifiers for method TestClass::__autoload():