Skip to content

Commit 9afea71

Browse files
author
Thies C. Arntzen
committed
debug_backtrace() now checks the complete argument-stack for consistency.
1 parent c8a659f commit 9afea71

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Zend/zend_builtin_functions.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,21 +1280,35 @@ ZEND_FUNCTION(debug_backtrace)
12801280
char *include_filename = NULL;
12811281
zval *stack_frame;
12821282
void **cur_arg_pos = EG(argument_stack).top_element;
1283+
void **args = cur_arg_pos;
1284+
int arg_stack_consitent = 0;
12831285

12841286
if (ZEND_NUM_ARGS()) {
12851287
WRONG_PARAM_COUNT;
12861288
}
12871289

1290+
while (--args >= EG(argument_stack).elements) {
1291+
if (*args--) {
1292+
break;
1293+
}
1294+
args -= *(ulong*)args;
1295+
1296+
if (args == EG(argument_stack).elements) {
1297+
arg_stack_consitent = 1;
1298+
break;
1299+
}
1300+
}
1301+
1302+
if (! arg_stack_consitent) {
1303+
zend_error(E_ERROR, "debug_backtrace(): Can't be called by function parameter");
1304+
}
1305+
12881306
ptr = EG(current_execute_data);
12891307

12901308
/* skip debug_backtrace() */
12911309
ptr = ptr->prev_execute_data;
12921310
cur_arg_pos -= 2;
12931311

1294-
if (ptr && cur_arg_pos[-1]) {
1295-
zend_error(E_ERROR, "debug_backtrace(): Can't be used as a function parameter");
1296-
}
1297-
12981312
array_init(return_value);
12991313

13001314
while (ptr) {

0 commit comments

Comments
 (0)