]> granicus.if.org Git - php/commitdiff
Fix broken memcmp
authorStanislav Malyshev <stas@php.net>
Thu, 7 Mar 2019 06:22:58 +0000 (22:22 -0800)
committerStanislav Malyshev <stas@php.net>
Thu, 7 Mar 2019 06:22:58 +0000 (22:22 -0800)
We can't really do memcmp("_call", "__callStatic", sizeof("__callStatic") -1),
neither should we memcmp constants at all.

Zend/zend_compile.c

index 082e59cf56280f719345c7b79cf7a7c91994e7ea..b6ed8c9c37732c4a9b449e7834794aed8a4448c3 100644 (file)
@@ -5496,11 +5496,11 @@ void zend_compile_closure_uses(zend_ast *ast) /* {{{ */
 }
 /* }}} */
 
-static void zend_check_magic_method_attr(uint32_t attr, const char* method) /* {{{ */
+static void zend_check_magic_method_attr(uint32_t attr, const char* method, zend_bool is_static) /* {{{ */
 {
-       if (memcmp(method, "__callStatic", sizeof("__callStatic") - 1) == 0) {
+       if (is_static) {
                if (!(attr & ZEND_ACC_PUBLIC) || !(attr & ZEND_ACC_STATIC)) {
-                       zend_error(E_WARNING, "The magic method __callStatic() must have public visibility and be static");
+                       zend_error(E_WARNING, "The magic method %s() must have public visibility and be static");
                }
        } else if (!(attr & ZEND_ACC_PUBLIC) || (attr & ZEND_ACC_STATIC)) {
                zend_error(E_WARNING,
@@ -5567,34 +5567,34 @@ void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_boo
        } else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
                ce->clone = (zend_function *) op_array;
        } else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__call");
+               zend_check_magic_method_attr(fn_flags, "__call", 0);
                ce->__call = (zend_function *) op_array;
        } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__callStatic");
+               zend_check_magic_method_attr(fn_flags, "__callStatic", 1);
                ce->__callstatic = (zend_function *) op_array;
        } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__get");
+               zend_check_magic_method_attr(fn_flags, "__get", 0);
                ce->__get = (zend_function *) op_array;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
        } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__set");
+               zend_check_magic_method_attr(fn_flags, "__set", 0);
                ce->__set = (zend_function *) op_array;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
        } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__unset");
+               zend_check_magic_method_attr(fn_flags, "__unset", 0);
                ce->__unset = (zend_function *) op_array;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
        } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__isset");
+               zend_check_magic_method_attr(fn_flags, "__isset", 0);
                ce->__isset = (zend_function *) op_array;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
        } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__toString");
+               zend_check_magic_method_attr(fn_flags, "__toString", 0);
                ce->__tostring = (zend_function *) op_array;
        } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__invoke");
+               zend_check_magic_method_attr(fn_flags, "__invoke", 0);
        } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__debugInfo");
+               zend_check_magic_method_attr(fn_flags, "__debugInfo", 0);
                ce->__debugInfo = (zend_function *) op_array;
        }