From: Antony Dovgal Date: Sat, 24 Feb 2007 21:30:48 +0000 (+0000) Subject: MFH: fix #40621 (Crash when constructor called inappropriately (statically)) X-Git-Tag: php-5.2.2RC1~280 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e058ba92f9e8fb7d0dcbfc365a9e93f63009f83b;p=php MFH: fix #40621 (Crash when constructor called inappropriately (statically)) --- diff --git a/Zend/tests/bug40621.phpt b/Zend/tests/bug40621.phpt new file mode 100644 index 0000000000..564ba55be2 --- /dev/null +++ b/Zend/tests/bug40621.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #40621 (Crash when constructor called inappropriately (statically)) +--FILE-- + +--EXPECTF-- +Strict Standards: Non-static method Foo::get() should not be called statically in %s on line %d + +Fatal error: Non-static method Foo::__construct() cannot be called statically in %s on line %d diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index a5e117daf0..0a4b0acc2e 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1765,7 +1765,7 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, ANY, CONST|TMP|VAR|UNUSED|CV) if(!ce->constructor) { zend_error_noreturn(E_ERROR, "Can not call constructor"); } - if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { + if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { zend_error(E_COMPILE_ERROR, "Cannot call private %s::__construct()", ce->name); } EX(fbc) = ce->constructor; diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index c91c9f4083..f3ff1b6331 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -694,7 +694,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_A if(!ce->constructor) { zend_error_noreturn(E_ERROR, "Can not call constructor"); } - if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { + if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { zend_error(E_COMPILE_ERROR, "Cannot call private %s::__construct()", ce->name); } EX(fbc) = ce->constructor; @@ -898,7 +898,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG if(!ce->constructor) { zend_error_noreturn(E_ERROR, "Can not call constructor"); } - if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { + if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { zend_error(E_COMPILE_ERROR, "Cannot call private %s::__construct()", ce->name); } EX(fbc) = ce->constructor; @@ -1059,7 +1059,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG if(!ce->constructor) { zend_error_noreturn(E_ERROR, "Can not call constructor"); } - if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { + if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { zend_error(E_COMPILE_ERROR, "Cannot call private %s::__construct()", ce->name); } EX(fbc) = ce->constructor; @@ -1219,7 +1219,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_ if(!ce->constructor) { zend_error_noreturn(E_ERROR, "Can not call constructor"); } - if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { + if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { zend_error(E_COMPILE_ERROR, "Cannot call private %s::__construct()", ce->name); } EX(fbc) = ce->constructor; @@ -1312,7 +1312,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS if(!ce->constructor) { zend_error_noreturn(E_ERROR, "Can not call constructor"); } - if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { + if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) { zend_error(E_COMPILE_ERROR, "Cannot call private %s::__construct()", ce->name); } EX(fbc) = ce->constructor;