Permalink
Browse files

Use a PHP version dependent conditional function for hash recursion p…

…rotection
  • Loading branch information...
derickr committed Jul 30, 2018
1 parent b769587 commit 707fdbce8614eb303956e26de9f1504b362a72cf
Showing with 136 additions and 180 deletions.
  1. +9 −30 xdebug_code_coverage.c
  2. +62 −0 xdebug_compat.c
  3. +5 −0 xdebug_compat.h
  4. +60 −150 xdebug_var.c
View
@@ -883,19 +883,14 @@ static int prefill_from_class_table(zend_class_entry *class_entry)
if (!(ce->ce_flags & ZEND_XDEBUG_VISITED)) {
zend_op_array *val;
ce->ce_flags |= ZEND_XDEBUG_VISITED;
#if PHP_VERSION_ID >= 70300
GC_PROTECT_RECURSION(&ce->function_table);
#else
ZEND_HASH_INC_APPLY_COUNT(&ce->function_table);
#endif
xdebug_zend_hash_apply_protection_begin(&ce->function_table);
ZEND_HASH_FOREACH_PTR(&ce->function_table, val) {
prefill_from_function_table(val);
} ZEND_HASH_FOREACH_END();
#if PHP_VERSION_ID >= 70300
GC_UNPROTECT_RECURSION(&ce->function_table);
#else
ZEND_HASH_DEC_APPLY_COUNT(&ce->function_table);
#endif
xdebug_zend_hash_apply_protection_end(&ce->function_table);
}
}
@@ -911,33 +906,17 @@ void xdebug_prefill_code_coverage(zend_op_array *op_array TSRMLS_DC)
prefill_from_oparray((char*) STR_NAME_VAL(op_array->filename), op_array TSRMLS_CC);
}
#if PHP_VERSION_ID >= 70300
GC_PROTECT_RECURSION(CG(function_table));
#else
ZEND_HASH_INC_APPLY_COUNT(CG(function_table));
#endif
xdebug_zend_hash_apply_protection_begin(CG(function_table));
ZEND_HASH_FOREACH_PTR(CG(function_table), function_op_array) {
prefill_from_function_table(function_op_array);
} ZEND_HASH_FOREACH_END();
#if PHP_VERSION_ID >= 70300
GC_UNPROTECT_RECURSION(CG(function_table));
#else
ZEND_HASH_DEC_APPLY_COUNT(CG(function_table));
#endif
xdebug_zend_hash_apply_protection_end(CG(function_table));
#if PHP_VERSION_ID >= 70300
GC_PROTECT_RECURSION(CG(class_table));
#else
ZEND_HASH_INC_APPLY_COUNT(CG(class_table));
#endif
xdebug_zend_hash_apply_protection_begin(CG(class_table));
ZEND_HASH_FOREACH_PTR(CG(class_table), class_entry) {
prefill_from_class_table(class_entry);
} ZEND_HASH_FOREACH_END();
#if PHP_VERSION_ID >= 70300
GC_UNPROTECT_RECURSION(CG(class_table));
#else
ZEND_HASH_DEC_APPLY_COUNT(CG(class_table));
#endif
xdebug_zend_hash_apply_protection_end(CG(class_table));
}
void xdebug_code_coverage_start_of_function(zend_op_array *op_array, char *function_name TSRMLS_DC)
View
@@ -216,3 +216,65 @@ zval *xdebug_read_property(zend_class_entry *ce, zval *exception, const char *na
return zend_read_property(ce, exception, name, length, flags, &dummy);
}
#ifdef ZEND_HASH_GET_APPLY_COUNT /* PHP 7.2 or earlier recursion protection */
zend_bool xdebug_zend_hash_is_recursive(HashTable* ht)
{
return (ZEND_HASH_GET_APPLY_COUNT(ht) > 0);
}
zend_bool xdebug_zend_hash_apply_protection_begin(HashTable* ht)
{
if (!ht) {
return 1;
}
if (ZEND_HASH_GET_APPLY_COUNT(ht) > 0) {
return 0;
}
if (ZEND_HASH_APPLY_PROTECTION(ht)) {
ZEND_HASH_INC_APPLY_COUNT(ht);
}
return 1;
}
zend_bool xdebug_zend_hash_apply_protection_end(HashTable* ht)
{
if (!ht) {
return 1;
}
if (ZEND_HASH_GET_APPLY_COUNT(ht) == 0) {
return 0;
}
if (ZEND_HASH_APPLY_PROTECTION(ht)) {
ZEND_HASH_DEC_APPLY_COUNT(ht);
}
return 1;
}
#else /* PHP 7.3 or later */
zend_bool xdebug_zend_hash_is_recursive(HashTable* ht)
{
return GC_IS_RECURSIVE(ht);
}
zend_bool xdebug_zend_hash_apply_protection_begin(zend_array* ht)
{
if (GC_IS_RECURSIVE(ht)) {
return 0;
}
if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) {
GC_PROTECT_RECURSION(ht);
}
return 1;
}
zend_bool xdebug_zend_hash_apply_protection_end(zend_array* ht)
{
if (!GC_IS_RECURSIVE(ht)) {
return 0;
}
if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) {
GC_UNPROTECT_RECURSION(ht);
}
return 1;
}
#endif
View
@@ -38,6 +38,11 @@ void xdebug_setcookie(const char *name, int name_len, char *value, int value_len
char *xdebug_get_compiled_variable_name(zend_op_array *op_array, uint32_t var, int *cv_len);
zval *xdebug_read_property(zend_class_entry *ce, zval *exception, const char *name, int length, int flags TSRMLS_DC);
/* Recursion protection is done differently from PHP 7.3 onwards */
zend_bool xdebug_zend_hash_is_recursive(HashTable* ht);
zend_bool xdebug_zend_hash_apply_protection_begin(HashTable* ht);
zend_bool xdebug_zend_hash_apply_protection_end(HashTable* ht);
# define XDEBUG_MAKE_STD_ZVAL(zv) \
zv = ecalloc(sizeof(zval), 1);
Oops, something went wrong.

0 comments on commit 707fdbc

Please sign in to comment.