Skip to content
Permalink
Browse files

Fixed issue #1700: Xdebug abuses possibilty immutable class flags

  • Loading branch information
derickr committed Aug 26, 2019
1 parent db03c42 commit ddecc4143c419bb7ba9cef285cb732dbc6d49bdd
Showing with 23 additions and 8 deletions.
  1. +1 −0 php_xdebug.h
  2. +4 −1 xdebug.c
  3. +18 −5 xdebug_code_coverage.c
  4. +0 −2 xdebug_private.h
@@ -210,6 +210,7 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug)
char *previous_mark_filename;
xdebug_coverage_file *previous_mark_file;
xdebug_path_info *paths_stack;
xdebug_hash *visited_classes;
xdebug_hash *visited_branches;
struct {
unsigned int size;
@@ -1372,7 +1372,8 @@ PHP_RINIT_FUNCTION(xdebug)
/* Initialize dump superglobals */
XG(dumped) = 0;

/* Initialize visisted branches hash */
/* Initialize visited classes and branches hash */
XG(visited_classes) = xdebug_hash_alloc(2048, NULL);
XG(visited_branches) = xdebug_hash_alloc(2048, NULL);

/* Initialize start time */
@@ -1454,6 +1455,8 @@ ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug)
xdebug_hash_destroy(XG(code_coverage_info));
XG(code_coverage_info) = NULL;

xdebug_hash_destroy(XG(visited_classes));
XG(visited_classes) = NULL;
xdebug_hash_destroy(XG(visited_branches));
XG(visited_branches) = NULL;

@@ -1047,16 +1047,29 @@ static int prefill_from_function_table(zend_op_array *opa)
return ZEND_HASH_APPLY_KEEP;
}

static int prefill_from_class_table(zend_class_entry *class_entry)
static int mark_class_as_visited(zend_class_entry *ce)
{
zend_class_entry *ce;
int already_visited = 0;
void *dummy; /* we only care about key existence, not value */
char *key = xdebug_sprintf("%08X", (uintptr_t) ce);
size_t key_len = strlen(key);

ce = class_entry;
if (xdebug_hash_find(XG(visited_classes), key, key_len, (void*) &dummy)) {
already_visited = 1;
} else {
xdebug_hash_add(XG(visited_classes), key, key_len, NULL);
}

xdfree(key);

return already_visited;
}

static int prefill_from_class_table(zend_class_entry *ce)
{
if (ce->type == ZEND_USER_CLASS) {
if (!(ce->ce_flags & ZEND_XDEBUG_VISITED)) {
if (mark_class_as_visited(ce)) {
zend_op_array *val;
ce->ce_flags |= ZEND_XDEBUG_VISITED;

xdebug_zend_hash_apply_protection_begin(&ce->function_table);

@@ -139,8 +139,6 @@ extern const char* xdebug_log_prefix[11];

#define XDEBUG_ERROR_ENCODING_NOT_SUPPORTED 900

#define ZEND_XDEBUG_VISITED 0x10000000

typedef struct _xdebug_func {
char *class;
char *function;

0 comments on commit ddecc41

Please sign in to comment.
You can’t perform that action at this time.