Skip to content

Commit 415aac5

Browse files
committed
simple ignore arguments in backtrace implementation
1 parent d924b42 commit 415aac5

5 files changed

+55
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Exceptions ignoring arguments
3+
--FILE--
4+
<?php
5+
$function = function(string $user, string $pass) {
6+
throw new Exception();
7+
};
8+
9+
ini_set("zend.backtrace_ignore_args", 1);
10+
11+
$function("secrets", "arewrong");
12+
?>
13+
--EXPECTF--
14+
Fatal error: Uncaught Exception in %sdebug_backtrace_ignore_args.php:3
15+
Stack trace:
16+
#0 %sdebug_backtrace_ignore_args.php(8): {closure}()
17+
#1 {main}
18+
thrown in %sdebug_backtrace_ignore_args.php on line 3
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
zend.backtrace_ignore_args does not interfere with debug_backtrace
3+
--FILE--
4+
<?php
5+
$function = function(string $user, string $pass, int $options = 0) {
6+
return debug_backtrace($options);
7+
};
8+
9+
ini_set("zend.backtrace_ignore_args", true);
10+
11+
$trace = $function("user", "pass");
12+
13+
if (!isset($trace[0]["args"])) { # args should exist
14+
var_dump($trace);
15+
exit;
16+
}
17+
18+
echo "OK\n";
19+
20+
$trace = $function("user", "pass", DEBUG_BACKTRACE_IGNORE_ARGS);
21+
22+
if (isset($trace[0]["args"])) { # args should be ignored
23+
var_dump($trace);
24+
exit;
25+
}
26+
27+
echo "OK\n";
28+
?>
29+
--EXPECT--
30+
OK
31+
OK

Zend/zend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ ZEND_INI_BEGIN()
174174
#ifdef ZEND_SIGNALS
175175
STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
176176
#endif
177+
STD_ZEND_INI_BOOLEAN("zend.backtrace_ignore_args", "0", ZEND_INI_ALL, OnUpdateBool, backtrace_ignore_args, zend_executor_globals, executor_globals)
177178
ZEND_INI_END()
178179

179180
ZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */

Zend/zend_exceptions.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type,
212212
object_properties_init(object, class_type);
213213

214214
if (EG(current_execute_data)) {
215-
zend_fetch_debug_backtrace(&trace, skip_top_traces, 0, 0);
215+
zend_fetch_debug_backtrace(&trace,
216+
skip_top_traces,
217+
EG(backtrace_ignore_args) ? DEBUG_BACKTRACE_IGNORE_ARGS : 0, 0);
216218
} else {
217219
array_init(&trace);
218220
}

Zend/zend_globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ struct _zend_executor_globals {
234234

235235
HashTable weakrefs;
236236

237+
zend_bool backtrace_ignore_args;
238+
237239
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
238240
};
239241

0 commit comments

Comments
 (0)