Skip to content

Commit ef68cd3

Browse files
ekinhbayarnikic
authored andcommitted
Fixed bug #77530: PHP crashes when parsing "(2)::class"
1 parent dc2ffde commit ef68cd3

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP NEWS
66
. Fixed bug #77339 (__callStatic may get incorrect arguments). (Dmitry)
77
. Fixed bug #77494 (Disabling class causes segfault on member access).
88
(Dmitry)
9+
. Fixed bug #77530 (PHP crashes when parsing `(2)::class`). (Ekin)
910

1011
- Curl:
1112
. Fixed bug #76675 (Segfault with H2 server push). (Pedro Magalhães)

Zend/tests/bug77530.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #77530: PHP crashes when parsing '(2)::class'
3+
--FILE--
4+
<?php
5+
6+
echo (2)::class;
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Illegal class name in %s on line %d

Zend/zend_compile.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,7 @@ static void zend_ensure_valid_class_fetch_type(uint32_t fetch_type) /* {{{ */
14941494
static zend_bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_ast *class_ast, zend_ast *name_ast, zend_bool constant) /* {{{ */
14951495
{
14961496
uint32_t fetch_type;
1497+
zval *class_name;
14971498

14981499
if (name_ast->kind != ZEND_AST_ZVAL) {
14991500
return 0;
@@ -1508,7 +1509,13 @@ static zend_bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_a
15081509
"Dynamic class names are not allowed in compile-time ::class fetch");
15091510
}
15101511

1511-
fetch_type = zend_get_class_fetch_type(zend_ast_get_str(class_ast));
1512+
class_name = zend_ast_get_zval(class_ast);
1513+
1514+
if (Z_TYPE_P(class_name) != IS_STRING) {
1515+
zend_error_noreturn(E_COMPILE_ERROR, "Illegal class name");
1516+
}
1517+
1518+
fetch_type = zend_get_class_fetch_type(Z_STR_P(class_name));
15121519
zend_ensure_valid_class_fetch_type(fetch_type);
15131520

15141521
switch (fetch_type) {

0 commit comments

Comments
 (0)