Fixed bug #77387 (Recursion detection broken when printing GLOBALS)

This commit is contained in:
Xinchen Hui 2019-01-02 16:42:21 +08:00
parent 476eba13d8
commit 384b02d058

View File

@ -376,17 +376,17 @@ ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
switch (Z_TYPE_P(expr)) { switch (Z_TYPE_P(expr)) {
case IS_ARRAY: case IS_ARRAY:
ZEND_PUTS("Array ("); ZEND_PUTS("Array (");
if (Z_REFCOUNTED_P(expr)) { if (!(GC_FLAGS(Z_ARRVAL_P(expr)) & GC_IMMUTABLE)) {
if (Z_IS_RECURSIVE_P(expr)) { if (GC_IS_RECURSIVE(Z_ARRVAL_P(expr))) {
ZEND_PUTS(" *RECURSION*"); ZEND_PUTS(" *RECURSION*");
return; return;
} }
Z_PROTECT_RECURSION_P(expr); GC_PROTECT_RECURSION(Z_ARRVAL_P(expr));
} }
print_flat_hash(Z_ARRVAL_P(expr)); print_flat_hash(Z_ARRVAL_P(expr));
ZEND_PUTS(")"); ZEND_PUTS(")");
if (Z_REFCOUNTED_P(expr)) { if (!(GC_FLAGS(Z_ARRVAL_P(expr)) & GC_IMMUTABLE)) {
Z_UNPROTECT_RECURSION_P(expr); GC_UNPROTECT_RECURSION(Z_ARRVAL_P(expr));
} }
break; break;
case IS_OBJECT: case IS_OBJECT:
@ -396,16 +396,16 @@ ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
zend_printf("%s Object (", ZSTR_VAL(class_name)); zend_printf("%s Object (", ZSTR_VAL(class_name));
zend_string_release_ex(class_name, 0); zend_string_release_ex(class_name, 0);
if (Z_IS_RECURSIVE_P(expr)) { if (GC_IS_RECURSIVE(Z_COUNTED_P(expr))) {
ZEND_PUTS(" *RECURSION*"); ZEND_PUTS(" *RECURSION*");
return; return;
} }
properties = Z_OBJPROP_P(expr); properties = Z_OBJPROP_P(expr);
if (properties) { if (properties) {
Z_PROTECT_RECURSION_P(expr); GC_PROTECT_RECURSION(Z_OBJ_P(expr));
print_flat_hash(properties); print_flat_hash(properties);
Z_UNPROTECT_RECURSION_P(expr); GC_UNPROTECT_RECURSION(Z_OBJ_P(expr));
} }
ZEND_PUTS(")"); ZEND_PUTS(")");
break; break;
@ -425,16 +425,16 @@ static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /*
switch (Z_TYPE_P(expr)) { switch (Z_TYPE_P(expr)) {
case IS_ARRAY: case IS_ARRAY:
smart_str_appends(buf, "Array\n"); smart_str_appends(buf, "Array\n");
if (Z_REFCOUNTED_P(expr)) { if (!(GC_FLAGS(Z_ARRVAL_P(expr)) & GC_IMMUTABLE)) {
if (Z_IS_RECURSIVE_P(expr)) { if (GC_IS_RECURSIVE(Z_ARRVAL_P(expr))) {
smart_str_appends(buf, " *RECURSION*"); smart_str_appends(buf, " *RECURSION*");
return; return;
} }
Z_PROTECT_RECURSION_P(expr); GC_PROTECT_RECURSION(Z_ARRVAL_P(expr));
} }
print_hash(buf, Z_ARRVAL_P(expr), indent, 0); print_hash(buf, Z_ARRVAL_P(expr), indent, 0);
if (Z_REFCOUNTED_P(expr)) { if (!(GC_FLAGS(Z_ARRVAL_P(expr)) & GC_IMMUTABLE)) {
Z_UNPROTECT_RECURSION_P(expr); GC_UNPROTECT_RECURSION(Z_ARRVAL_P(expr));
} }
break; break;
case IS_OBJECT: case IS_OBJECT:
@ -446,7 +446,7 @@ static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /*
zend_string_release_ex(class_name, 0); zend_string_release_ex(class_name, 0);
smart_str_appends(buf, " Object\n"); smart_str_appends(buf, " Object\n");
if (Z_IS_RECURSIVE_P(expr)) { if (GC_IS_RECURSIVE(Z_OBJ_P(expr))) {
smart_str_appends(buf, " *RECURSION*"); smart_str_appends(buf, " *RECURSION*");
return; return;
} }
@ -455,9 +455,9 @@ static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /*
break; break;
} }
Z_PROTECT_RECURSION_P(expr); GC_PROTECT_RECURSION(Z_OBJ_P(expr));
print_hash(buf, properties, indent, 1); print_hash(buf, properties, indent, 1);
Z_UNPROTECT_RECURSION_P(expr); GC_UNPROTECT_RECURSION(Z_OBJ_P(expr));
zend_release_properties(properties); zend_release_properties(properties);
break; break;