Skip to content

Commit 5c6d750

Browse files
GH-18463: skip recursion protection for internal constants
Internal constants are persisted; if a user error handler triggers bailout before the recursion flag is removed then a subsequent request (e.g. with `--repeat 2`) will start with that flag already applied. Internal constants can presumably be trusted not to use deprecation messages that come from recursive attributes.
1 parent e18498e commit 5c6d750

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-18463: Recursion protection should not be applied to internal class constants
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
function handler($errno, $errstr, $errfile, $errline) {
9+
echo "$errstr in $errfile on line $errline\n";
10+
eval('class string {}');
11+
}
12+
13+
set_error_handler('handler');
14+
15+
var_dump(_ZendTestClass::ZEND_TEST_DEPRECATED);
16+
?>
17+
--EXPECTF--
18+
Constant _ZendTestClass::ZEND_TEST_DEPRECATED is deprecated in %s on line %d
19+
20+
Fatal error: Cannot use "string" as a class name as it is reserved in %s(%d) : eval()'d code on line %d

Zend/zend_constants.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@
3232
#define CONST_IS_RECURSIVE(c) (Z_CONSTANT_FLAGS((c)->value) & CONST_RECURSIVE)
3333
#define CONST_PROTECT_RECURSION(c) \
3434
do { \
35-
Z_CONSTANT_FLAGS((c)->value) |= CONST_RECURSIVE; \
35+
/* Ignored for internal constants, GH-18463 */ \
36+
if (ZEND_CONSTANT_MODULE_NUMBER(c) == PHP_USER_CONSTANT) { \
37+
Z_CONSTANT_FLAGS((c)->value) |= CONST_RECURSIVE; \
38+
} \
3639
} while (0)
3740
#define CONST_UNPROTECT_RECURSION(c) \
3841
do { \
39-
Z_CONSTANT_FLAGS((c)->value) &= ~CONST_RECURSIVE; \
42+
/* Ignored for internal constants, GH-18463 */ \
43+
if (ZEND_CONSTANT_MODULE_NUMBER(c) == PHP_USER_CONSTANT) { \
44+
Z_CONSTANT_FLAGS((c)->value) &= ~CONST_RECURSIVE; \
45+
} \
4046
} while (0)
4147

4248
#define PHP_USER_CONSTANT 0x7fffff /* a constant defined in user space */

0 commit comments

Comments
 (0)