Skip to content

Commit d79310b

Browse files
committed
Fix GH-22849: error_include_args=1 mishandled for include()
include and friends aren't functions, but constructs of the engine. Special-case them and snarf their argument for display.
1 parent f2b6b7f commit d79310b

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

Zend/tests/gh22849.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
PHP 8.6 error_include_args=1 mishandled for include()
3+
--INI--
4+
error_include_args=On
5+
--FILE--
6+
<?php
7+
8+
function foo() {
9+
eval('include("does not exist");');
10+
include("does not exist");
11+
include_once("does not exist");
12+
require("does not exist");
13+
}
14+
15+
foo(1, 2);
16+
?>
17+
--EXPECTF--
18+
Warning: include('does not exist'): Failed to open stream: No such file or directory in %s on line %d
19+
20+
Warning: include('does not exist'): Failed opening 'does not exist' for inclusion (include_path='%s') in %s on line %d
21+
22+
Warning: include('does not exist'): Failed to open stream: No such file or directory in %s on line %d
23+
24+
Warning: include('does not exist'): Failed opening 'does not exist' for inclusion (include_path='%s') in %s on line %d
25+
26+
Warning: include_once('does not exist'): Failed to open stream: No such file or directory in %s on line %d
27+
28+
Warning: include_once('does not exist'): Failed opening 'does not exist' for inclusion (include_path='%s') in %s on line %d
29+
30+
Warning: require('does not exist'): Failed to open stream: No such file or directory in %s on line %d
31+
32+
Fatal error: Uncaught Error: Failed opening required 'does not exist' (include_path='%s') in %s:%d
33+
Stack trace:
34+
#0 %s(%d): foo(1, 2)
35+
#1 {main}
36+
thrown in %s on line %d

Zend/zend_exceptions.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,20 @@ ZEND_API zend_string *zend_trace_function_args_to_string(const HashTable *frame)
630630
/* {{{ Gets the currently executing function's arguments as a string. Used by php_verror. */
631631
ZEND_API zend_string *zend_trace_current_function_args_string(void) {
632632
zend_string *dynamic_params = NULL;
633+
/* Special case: require_once/include_once aren't functions, but we
634+
* want to capture their arguments anyways.
635+
*/
636+
zend_execute_data *execute_data = EG(current_execute_data);
637+
if (execute_data && execute_data->func
638+
&& ZEND_USER_CODE(execute_data->func->common.type)
639+
&& (execute_data->opline->opcode == ZEND_INCLUDE_OR_EVAL)) {
640+
zval *inc_filename = RT_CONSTANT(execute_data->opline, execute_data->opline->op1);
641+
smart_str str = {0};
642+
build_trace_args(inc_filename, &str);
643+
dynamic_params = smart_str_extract(&str);
644+
return dynamic_params;
645+
}
646+
633647
/* get a backtrace to snarf function args */
634648
zval backtrace;
635649
zend_fetch_debug_backtrace(&backtrace, /* skip_last */ 0, /* options */ 0, /* limit */ 1);

0 commit comments

Comments
 (0)