]> granicus.if.org Git - php/commitdiff
Check `__set_state` structure
authorGabriel Caruso <carusogabriel34@gmail.com>
Sun, 26 Apr 2020 02:31:47 +0000 (04:31 +0200)
committerGabriel Caruso <carusogabriel34@gmail.com>
Tue, 28 Apr 2020 15:02:03 +0000 (17:02 +0200)
Fix Bug #79521.

Closes GH-5462.

NEWS
Zend/tests/magic_methods_set_state.phpt [new file with mode: 0644]
Zend/zend_compile.c
ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt

diff --git a/NEWS b/NEWS
index 4cc5691d9ea9867f3ddd985b7b568545c3c3a07c..a6e2915ab6503afb3e85f9652d92c566c654fa43 100644 (file)
--- 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 (file)
index 0000000..389798e
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Testing __set_state() declaration with wrong modifier
+--FILE--
+<?php
+
+class Foo {
+    function __set_state()
+    {
+    }
+}
+
+?>
+--EXPECTF--
+Warning: The magic method Foo::__set_state() must be static in %s on line %d
index 7c84456a6ff9c57c3fb768b23c8e03d7e380adcb..0923aa71415cdcc229feb05ca31103d8f102491c 100644 (file)
@@ -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;
index 70038c31a088d4ef042c53b4e7c7008245352caf..e5e967e28e82aa8cce03e5773838899fea40b2d6 100644 (file)
@@ -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():