From: Antony Dovgal Date: Tue, 13 Nov 2007 16:51:22 +0000 (+0000) Subject: disallow multiple access modifiers and 'abstract abstract' methods X-Git-Tag: RELEASE_2_0_0a1~1378 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c7296f165f6f95a46aa4f0632bec15da5632af2;p=php disallow multiple access modifiers and 'abstract abstract' methods add tests --- diff --git a/Zend/tests/access_modifiers_001.phpt b/Zend/tests/access_modifiers_001.phpt new file mode 100644 index 0000000000..989b926be3 --- /dev/null +++ b/Zend/tests/access_modifiers_001.phpt @@ -0,0 +1,14 @@ +--TEST-- +using multiple access modifiers (methods) +--FILE-- + +--EXPECTF-- +Fatal error: Multiple access type modifiers are not allowed in %s on line %d diff --git a/Zend/tests/access_modifiers_002.phpt b/Zend/tests/access_modifiers_002.phpt new file mode 100644 index 0000000000..cc5df306f1 --- /dev/null +++ b/Zend/tests/access_modifiers_002.phpt @@ -0,0 +1,13 @@ +--TEST-- +using multiple access modifiers (attributes) +--FILE-- + +--EXPECTF-- +Fatal error: Multiple access type modifiers are not allowed in %s on line %d diff --git a/Zend/tests/access_modifiers_003.phpt b/Zend/tests/access_modifiers_003.phpt new file mode 100644 index 0000000000..9c5a20a28c --- /dev/null +++ b/Zend/tests/access_modifiers_003.phpt @@ -0,0 +1,13 @@ +--TEST-- +using multiple access modifiers (classes) +--FILE-- + +--EXPECTF-- +Parse error: syntax error, unexpected T_FINAL, expecting T_CLASS in %s on line %d diff --git a/Zend/tests/access_modifiers_004.phpt b/Zend/tests/access_modifiers_004.phpt new file mode 100644 index 0000000000..c023d2cb6d --- /dev/null +++ b/Zend/tests/access_modifiers_004.phpt @@ -0,0 +1,14 @@ +--TEST-- +using multiple access modifiers (abstract methods) +--FILE-- + +--EXPECTF-- +Fatal error: Multiple abstract modifiers are not allowed in %s on line %d diff --git a/Zend/tests/access_modifiers_005.phpt b/Zend/tests/access_modifiers_005.phpt new file mode 100644 index 0000000000..b32394d7f6 --- /dev/null +++ b/Zend/tests/access_modifiers_005.phpt @@ -0,0 +1,14 @@ +--TEST-- +using multiple access modifiers (final methods) +--FILE-- + +--EXPECTF-- +Fatal error: Multiple final modifiers are not allowed in %s on line %d diff --git a/Zend/tests/access_modifiers_006.phpt b/Zend/tests/access_modifiers_006.phpt new file mode 100644 index 0000000000..293fc1c64c --- /dev/null +++ b/Zend/tests/access_modifiers_006.phpt @@ -0,0 +1,14 @@ +--TEST-- +using multiple access modifiers (static methods) +--FILE-- + +--EXPECTF-- +Fatal error: Multiple static modifiers are not allowed in %s on line %d diff --git a/Zend/tests/access_modifiers_007.phpt b/Zend/tests/access_modifiers_007.phpt new file mode 100644 index 0000000000..26779e6e68 --- /dev/null +++ b/Zend/tests/access_modifiers_007.phpt @@ -0,0 +1,13 @@ +--TEST-- +abstract final methods errmsg +--FILE-- + +--EXPECTF-- +Fatal error: Cannot use the final modifier on an abstract class member in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index f674cd4b25..9155fa77c2 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1126,10 +1126,21 @@ void zend_do_free(znode *op1 TSRMLS_DC) /* {{{ */ int zend_do_verify_access_types(znode *current_access_type, znode *new_modifier) /* {{{ */ { if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_PPP_MASK) - && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_PPP_MASK) - && ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_PPP_MASK) != (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_PPP_MASK))) { + && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_PPP_MASK)) { zend_error(E_COMPILE_ERROR, "Multiple access type modifiers are not allowed"); } + if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_ABSTRACT) + && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_ABSTRACT)) { + zend_error(E_COMPILE_ERROR, "Multiple abstract modifiers are not allowed"); + } + if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_STATIC) + && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_STATIC)) { + zend_error(E_COMPILE_ERROR, "Multiple static modifiers are not allowed"); + } + if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_FINAL) + && (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_FINAL)) { + zend_error(E_COMPILE_ERROR, "Multiple final modifiers are not allowed"); + } if (((Z_LVAL(current_access_type->u.constant) | Z_LVAL(new_modifier->u.constant)) & (ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL)) == (ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL)) { zend_error(E_COMPILE_ERROR, "Cannot use the final modifier on an abstract class member"); }