Skip to content
Permalink
Browse files
Fixed issue #1794: Replace the filter's blacklist/whitelist with excl…
…ude/include
  • Loading branch information
derickr committed Jun 6, 2020
1 parent f2cd83c commit 63b43b51e43b794cf8cd740e54089b2b7320fbe1
Showing 25 changed files with 198 additions and 198 deletions.
@@ -49,13 +49,13 @@ void xdebug_filter_register_constants(INIT_FUNC_ARGS)
REGISTER_LONG_CONSTANT("XDEBUG_FILTER_CODE_COVERAGE", XDEBUG_FILTER_CODE_COVERAGE, CONST_CS | CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("XDEBUG_FILTER_NONE", XDEBUG_FILTER_NONE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_PATH_WHITELIST", XDEBUG_PATH_WHITELIST, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_PATH_BLACKLIST", XDEBUG_PATH_BLACKLIST, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_NAMESPACE_WHITELIST", XDEBUG_NAMESPACE_WHITELIST, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_NAMESPACE_BLACKLIST", XDEBUG_NAMESPACE_BLACKLIST, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_PATH_INCLUDE", XDEBUG_PATH_INCLUDE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_PATH_EXCLUDE", XDEBUG_PATH_EXCLUDE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_NAMESPACE_INCLUDE", XDEBUG_NAMESPACE_INCLUDE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("XDEBUG_NAMESPACE_EXCLUDE", XDEBUG_NAMESPACE_EXCLUDE, CONST_CS | CONST_PERSISTENT);
}

static int xdebug_filter_match_path_whitelist(function_stack_entry *fse, long *filtered_flag, char *filter)
static int xdebug_filter_match_path_include(function_stack_entry *fse, long *filtered_flag, char *filter)
{
if (strncasecmp(filter, fse->filename, strlen(filter)) == 0) {
*filtered_flag = 0;
@@ -64,7 +64,7 @@ static int xdebug_filter_match_path_whitelist(function_stack_entry *fse, long *f
return 0;
}

static int xdebug_filter_match_path_blacklist(function_stack_entry *fse, long *filtered_flag, char *filter)
static int xdebug_filter_match_path_exclude(function_stack_entry *fse, long *filtered_flag, char *filter)
{
if (strncasecmp(filter, fse->filename, strlen(filter)) == 0) {
*filtered_flag = 1;
@@ -73,7 +73,7 @@ static int xdebug_filter_match_path_blacklist(function_stack_entry *fse, long *f
return 0;
}

static int xdebug_filter_match_namespace_whitelist(function_stack_entry *fse, long *filtered_flag, char *filter)
static int xdebug_filter_match_namespace_include(function_stack_entry *fse, long *filtered_flag, char *filter)
{
if (!fse->function.class && strlen(filter) == 0) {
*filtered_flag = 0;
@@ -86,7 +86,7 @@ static int xdebug_filter_match_namespace_whitelist(function_stack_entry *fse, lo
return 0;
}

static int xdebug_filter_match_namespace_blacklist(function_stack_entry *fse, long *filtered_flag, char *filter)
static int xdebug_filter_match_namespace_exclude(function_stack_entry *fse, long *filtered_flag, char *filter)
{
if (!fse->function.class && strlen(filter) == 0) {
*filtered_flag = 1;
@@ -110,34 +110,34 @@ void xdebug_filter_run_internal(function_stack_entry *fse, int group, long *filt
le = XDEBUG_LLIST_HEAD(filters);

switch (type) {
case XDEBUG_PATH_WHITELIST:
case XDEBUG_PATH_INCLUDE:
*filtered_flag = 1;
if (group == XDEBUG_FILTER_CODE_COVERAGE && fse->function.type & XFUNC_INCLUDES) {
tmp_fse.filename = fse->include_filename;
fse = &tmp_fse;
}

filter_to_run = xdebug_filter_match_path_whitelist;
filter_to_run = xdebug_filter_match_path_include;
break;

case XDEBUG_PATH_BLACKLIST:
case XDEBUG_PATH_EXCLUDE:
*filtered_flag = 0;
if (group == XDEBUG_FILTER_CODE_COVERAGE && fse->function.type & XFUNC_INCLUDES) {
tmp_fse.filename = fse->include_filename;
fse = &tmp_fse;
}

filter_to_run = xdebug_filter_match_path_blacklist;
filter_to_run = xdebug_filter_match_path_exclude;
break;

case XDEBUG_NAMESPACE_WHITELIST:
case XDEBUG_NAMESPACE_INCLUDE:
*filtered_flag = 1;
filter_to_run = xdebug_filter_match_namespace_whitelist;
filter_to_run = xdebug_filter_match_namespace_include;
break;

case XDEBUG_NAMESPACE_BLACKLIST:
case XDEBUG_NAMESPACE_EXCLUDE:
*filtered_flag = 0;
filter_to_run = xdebug_filter_match_namespace_blacklist;
filter_to_run = xdebug_filter_match_namespace_exclude;
break;

default:
@@ -186,8 +186,8 @@ PHP_FUNCTION(xdebug_set_filter)
case XDEBUG_FILTER_CODE_COVERAGE:
filter_list = &XG_BASE(filters_code_coverage);
XG_BASE(filter_type_code_coverage) = XDEBUG_FILTER_NONE;
if (filter_type == XDEBUG_NAMESPACE_WHITELIST || filter_type == XDEBUG_NAMESPACE_BLACKLIST) {
php_error(E_WARNING, "The code coverage filter (XDEBUG_FILTER_CODE_COVERAGE) only supports the XDEBUG_PATH_WHITELIST, XDEBUG_PATH_BLACKLIST, and XDEBUG_FILTER_NONE filter types");
if (filter_type == XDEBUG_NAMESPACE_INCLUDE || filter_type == XDEBUG_NAMESPACE_EXCLUDE) {
php_error(E_WARNING, "The code coverage filter (XDEBUG_FILTER_CODE_COVERAGE) only supports the XDEBUG_PATH_INCLUDE, XDEBUG_PATH_EXCLUDE, and XDEBUG_FILTER_NONE filter types");
return;
}
break;
@@ -198,10 +198,10 @@ PHP_FUNCTION(xdebug_set_filter)
}

if (
filter_type == XDEBUG_PATH_WHITELIST ||
filter_type == XDEBUG_PATH_BLACKLIST ||
filter_type == XDEBUG_NAMESPACE_WHITELIST ||
filter_type == XDEBUG_NAMESPACE_BLACKLIST ||
filter_type == XDEBUG_PATH_INCLUDE ||
filter_type == XDEBUG_PATH_EXCLUDE ||
filter_type == XDEBUG_NAMESPACE_INCLUDE ||
filter_type == XDEBUG_NAMESPACE_EXCLUDE ||
filter_type == XDEBUG_FILTER_NONE
) {
switch (filter_group) {
@@ -214,7 +214,7 @@ PHP_FUNCTION(xdebug_set_filter)
break;
}
} else {
php_error(E_WARNING, "Filter type needs to be one of XDEBUG_PATH_WHITELIST, XDEBUG_PATH_BLACKLIST, XDEBUG_NAMESPACE_WHITELIST, XDEBUG_NAMESPACE_BLACKLIST, or XDEBUG_FILTER_NONE");
php_error(E_WARNING, "Filter type needs to be one of XDEBUG_PATH_INCLUDE, XDEBUG_PATH_EXCLUDE, XDEBUG_NAMESPACE_INCLUDE, XDEBUG_NAMESPACE_EXCLUDE, or XDEBUG_FILTER_NONE");
return;
}

@@ -32,10 +32,10 @@ void xdebug_filter_run_internal(function_stack_entry *fse, int group, long *filt
#define XDEBUG_FILTER_TRACING 0x100
#define XDEBUG_FILTER_CODE_COVERAGE 0x200

#define XDEBUG_PATH_WHITELIST 0x01
#define XDEBUG_PATH_BLACKLIST 0x02
#define XDEBUG_NAMESPACE_WHITELIST 0x11
#define XDEBUG_NAMESPACE_BLACKLIST 0x12
#define XDEBUG_PATH_INCLUDE 0x01
#define XDEBUG_PATH_EXCLUDE 0x02
#define XDEBUG_NAMESPACE_INCLUDE 0x11
#define XDEBUG_NAMESPACE_EXCLUDE 0x12

PHP_FUNCTION(xdebug_set_filter);

@@ -1867,7 +1867,7 @@ static int attach_context_vars(xdebug_xml_node *node, xdebug_var_export_options
tmp_hash = xdebug_declared_var_hash_from_llist(fse->declared_vars);

/* Check for dynamically defined variables, but make sure we don't already
* have them. Also blacklist superglobals and argv/argc */
* have them. Also exclude superglobals and argv/argc */
if (xdebug_lib_has_active_symbol_table()) {
zend_hash_apply_with_arguments(xdebug_lib_get_active_symbol_table(), (apply_func_args_t) xdebug_add_filtered_symboltable_var, 1, tmp_hash);
}
@@ -5,18 +5,18 @@ html_errors=0
display_errors=1
--FILE--
<?php
xdebug_set_filter(42, XDEBUG_PATH_BLACKLIST, [ "xdebug" ] );
xdebug_set_filter(42, XDEBUG_PATH_EXCLUDE, [ "xdebug" ] );

xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, 42, [ "xdebug" ] );

xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_NAMESPACE_BLACKLIST, [ "xdebug" ] );
xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_NAMESPACE_WHITELIST, [ "xdebug" ] );
xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_NAMESPACE_EXCLUDE, [ "xdebug" ] );
xdebug_set_filter(XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_NAMESPACE_INCLUDE, [ "xdebug" ] );
?>
--EXPECTF--
Warning: Filter group needs to be one of XDEBUG_FILTER_TRACING or XDEBUG_FILTER_CODE_COVERAGE in %sfilter-errors.php on line 2

Warning: Filter type needs to be one of XDEBUG_PATH_WHITELIST, XDEBUG_PATH_BLACKLIST, XDEBUG_NAMESPACE_WHITELIST, XDEBUG_NAMESPACE_BLACKLIST, or XDEBUG_FILTER_NONE in %sfilter-errors.php on line 4
Warning: Filter type needs to be one of XDEBUG_PATH_INCLUDE, XDEBUG_PATH_EXCLUDE, XDEBUG_NAMESPACE_INCLUDE, XDEBUG_NAMESPACE_EXCLUDE, or XDEBUG_FILTER_NONE in %sfilter-errors.php on line 4

Warning: The code coverage filter (XDEBUG_FILTER_CODE_COVERAGE) only supports the XDEBUG_PATH_WHITELIST, XDEBUG_PATH_BLACKLIST, and XDEBUG_FILTER_NONE filter types in %sfilter-errors.php on line 6
Warning: The code coverage filter (XDEBUG_FILTER_CODE_COVERAGE) only supports the XDEBUG_PATH_INCLUDE, XDEBUG_PATH_EXCLUDE, and XDEBUG_FILTER_NONE filter types in %sfilter-errors.php on line 6

Warning: The code coverage filter (XDEBUG_FILTER_CODE_COVERAGE) only supports the XDEBUG_PATH_WHITELIST, XDEBUG_PATH_BLACKLIST, and XDEBUG_FILTER_NONE filter types in %sfilter-errors.php on line 7
Warning: The code coverage filter (XDEBUG_FILTER_CODE_COVERAGE) only supports the XDEBUG_PATH_INCLUDE, XDEBUG_PATH_EXCLUDE, and XDEBUG_FILTER_NONE filter types in %sfilter-errors.php on line 7
@@ -1,5 +1,5 @@
--TEST--
Filtered stack traces: namespace blacklist [1]
Filtered stack traces: namespace exclude [1]
--INI--
xdebug.mode=display
xdebug.collect_params=4
@@ -15,26 +15,26 @@ $three = new \Stack\Three( new stdClass );
$two = new \Stack\Two( $three );
$one = new \Stack\One( $two );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ 'Stack\One' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_EXCLUDE, [ 'Stack\One' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ '\Stack\One' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_EXCLUDE, [ '\Stack\One' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ '\Stack\One', 'Stack\Two' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_EXCLUDE, [ '\Stack\One', 'Stack\Two' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ 'Stack\Two', 'Stack\Three' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_EXCLUDE, [ 'Stack\Two', 'Stack\Three' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_BLACKLIST, [ '', 'Stack\Two' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_EXCLUDE, [ '', 'Stack\Two' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );
?>
--EXPECTF--
Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-001.php:0
%w%f %w%d 1. {main}() %sstack-filter-ns-exclude-001.php:0
%w%f %w%d 3. Stack\Two->callObj($name = 'error', ...$arguments = variadic('Error triggered!')) %sone.php:13
%w%f %w%d 4. Stack\Three->error($value = 'Error triggered!') %stwo.php:13
%w%f %w%d 5. trigger_error('Error triggered!', 512) %sthree.php:18
@@ -43,7 +43,7 @@ Call Stack:
Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-001.php:0
%w%f %w%d 1. {main}() %sstack-filter-ns-exclude-001.php:0
%w%f %w%d 3. Stack\Two->callObj($name = 'error', ...$arguments = variadic('Error triggered!')) %sone.php:13
%w%f %w%d 4. Stack\Three->error($value = 'Error triggered!') %stwo.php:13
%w%f %w%d 5. trigger_error('Error triggered!', 512) %sthree.php:18
@@ -52,22 +52,22 @@ Call Stack:
Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-001.php:0
%w%f %w%d 1. {main}() %sstack-filter-ns-exclude-001.php:0
%w%f %w%d 4. Stack\Three->error($value = 'Error triggered!') %stwo.php:13
%w%f %w%d 5. trigger_error('Error triggered!', 512) %sthree.php:18


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-black-001.php:22
%w%f %w%d 1. {main}() %sstack-filter-ns-exclude-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-exclude-001.php:22
%w%f %w%d 5. trigger_error('Error triggered!', 512) %sthree.php:18


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-black-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-black-001.php:25
%w%f %w%d 1. {main}() %sstack-filter-ns-exclude-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-exclude-001.php:25
%w%f %w%d 4. Stack\Three->error($value = 'Error triggered!') %stwo.php:13
@@ -1,5 +1,5 @@
--TEST--
Filtered stack traces: namespace whitelist [1]
Filtered stack traces: namespace include [1]
--INI--
xdebug.mode=display
xdebug.collect_params=4
@@ -15,55 +15,55 @@ $three = new \Stack\Three( new stdClass );
$two = new \Stack\Two( $three );
$one = new \Stack\One( $two );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_WHITELIST, [ 'Stack\One' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_INCLUDE, [ 'Stack\One' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_WHITELIST, [ '\Stack\One' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_INCLUDE, [ '\Stack\One' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_WHITELIST, [ '\Stack\One', 'Stack\Two' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_INCLUDE, [ '\Stack\One', 'Stack\Two' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_WHITELIST, [ 'Stack\Two', 'Stack\Three' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_INCLUDE, [ 'Stack\Two', 'Stack\Three' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );

xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_WHITELIST, [ '', 'Stack\Two' ] );
xdebug_set_filter(XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_INCLUDE, [ '', 'Stack\Two' ] );
$one->callObj( 'callObj', 'error', 'Error triggered!' );
?>
--EXPECTF--
Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-white-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-white-001.php:13
%w%f %w%d 1. {main}() %sstack-filter-ns-include-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-include-001.php:13


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-white-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-white-001.php:16
%w%f %w%d 1. {main}() %sstack-filter-ns-include-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-include-001.php:16


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-white-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-white-001.php:19
%w%f %w%d 1. {main}() %sstack-filter-ns-include-001.php:0
%w%f %w%d 2. Stack\One->callObj($name = 'callObj', ...$arguments = variadic('error', 'Error triggered!')) %sstack-filter-ns-include-001.php:19
%w%f %w%d 3. Stack\Two->callObj($name = 'error', ...$arguments = variadic('Error triggered!')) %sone.php:13


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-white-001.php:0
%w%f %w%d 1. {main}() %sstack-filter-ns-include-001.php:0
%w%f %w%d 3. Stack\Two->callObj($name = 'error', ...$arguments = variadic('Error triggered!')) %sone.php:13
%w%f %w%d 4. Stack\Three->error($value = 'Error triggered!') %stwo.php:13


Warning: Error triggered! in %sthree.php on line 18

Call Stack:
%w%f %w%d 1. {main}() %sstack-filter-ns-white-001.php:0
%w%f %w%d 1. {main}() %sstack-filter-ns-include-001.php:0
%w%f %w%d 3. Stack\Two->callObj($name = 'error', ...$arguments = variadic('Error triggered!')) %sone.php:13
%w%f %w%d 5. trigger_error('Error triggered!', 512) %sthree.php:18

1 comment on commit 63b43b5

@evonicgu
Copy link

@evonicgu evonicgu commented on 63b43b5 Aug 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're just wasting time

Please sign in to comment.