Skip to content

Commit 23c65a8

Browse files
committed
Fix #77638: var_export'ing certain class instances segfaults
If objects return immutable property hash tables (typically, `zend_empty_array`), we must not try to apply recursion protection on those.
1 parent bb30fe9 commit 23c65a8

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ PHP NEWS
2121

2222
- Standard:
2323
. Fixed bug #78759 (array_search in $GLOBALS). (Nikita)
24+
. Fixed bug #77638 (var_export'ing certain class instances segfaults). (cmb)
2425

2526
21 Nov 2019, PHP 7.3.12
2627

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #77638 (var_export'ing certain class instances segfaults)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
var_export(new COM("Scripting.Dictionary"));
10+
?>
11+
--EXPECT--
12+
com::__set_state(array(
13+
))

ext/standard/var.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
524524
zend_error(E_WARNING, "var_export does not handle circular references");
525525
return;
526526
} else {
527-
GC_PROTECT_RECURSION(myht);
527+
GC_TRY_PROTECT_RECURSION(myht);
528528
}
529529
}
530530
if (level > 1) {
@@ -544,7 +544,7 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
544544
ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, val) {
545545
php_object_element_export(val, index, key, level, buf);
546546
} ZEND_HASH_FOREACH_END();
547-
GC_UNPROTECT_RECURSION(myht);
547+
GC_TRY_UNPROTECT_RECURSION(myht);
548548
}
549549
if (level > 1) {
550550
buffer_append_spaces(buf, level - 1);

0 commit comments

Comments
 (0)