Skip to content

Commit 8ba1cae

Browse files
committed
simple ignore arguments in exceptions implementation
1 parent 68785c0 commit 8ba1cae

6 files changed

+36
-1
lines changed

Zend/tests/exception_ignore_args.phpt

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.exception_ignore_args", 1);
10+
11+
$function("secrets", "arewrong");
12+
?>
13+
--EXPECTF--
14+
Fatal error: Uncaught Exception in %sexception_ignore_args.php:3
15+
Stack trace:
16+
#0 %sexception_ignore_args.php(8): {closure}()
17+
#1 {main}
18+
thrown in %sexception_ignore_args.php on line 3

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.exception_ignore_args", "0", ZEND_INI_ALL, OnUpdateBool, exception_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(exception_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 exception_ignore_args;
238+
237239
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
238240
};
239241

php.ini-development

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ zend.enable_gc = On
354354
; Default: ""
355355
;zend.script_encoding =
356356

357+
; Allows to include or exclude arguments from stack traces generated for exceptions
358+
; Default: Off
359+
zend.exception_ignore_args = Off
360+
357361
;;;;;;;;;;;;;;;;;
358362
; Miscellaneous ;
359363
;;;;;;;;;;;;;;;;;
@@ -1579,6 +1583,8 @@ zend.assertions = 1
15791583
; http://php.net/assert.quiet-eval
15801584
;assert.quiet_eval = 0
15811585

1586+
1587+
15821588
[COM]
15831589
; path to a file containing GUIDs, IIDs or filenames of files with TypeLibs
15841590
; http://php.net/com.typelib-file

php.ini-production

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ zend.enable_gc = On
359359
; Default: ""
360360
;zend.script_encoding =
361361

362+
; Allows to include or exclude arguments from stack traces generated for exceptions
363+
; Default: Off
364+
; In production, it is recommended to turn this setting on to prohibit the output
365+
; of sensitive information in stack traces
366+
zend.exception_ignore_args = On
367+
362368
;;;;;;;;;;;;;;;;;
363369
; Miscellaneous ;
364370
;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)