Skip to content

Commit 32e268f

Browse files
authored
zend: Remove zend_execute_scripts() (#23864)
This function is unsafe, because it reused the `retval` for each execution, without clearing it in-between each script, leading to memory leaks. Instead of fixing it, we just remove it: Writing a loop yourself is not much more complicated than using this variadic function and provides more flexibility.
1 parent 84514fd commit 32e268f

6 files changed

Lines changed: 7 additions & 29 deletions

File tree

‎UPGRADING.INTERNALS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ PHP 8.7 INTERNALS UPGRADE NOTES
1414
1. Internal API changes
1515
========================
1616

17+
- Removed zend_execute_scripts(). Manually call zend_execute_script() in a loop
18+
instead.
19+
1720
========================
1821
2. Build system changes
1922
========================

‎Zend/zend.c‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,30 +1996,6 @@ ZEND_API zend_result zend_execute_script(int type, zval *retval, zend_file_handl
19961996
return ret;
19971997
}
19981998

1999-
ZEND_API zend_result zend_execute_scripts(int type, zval *retval, int file_count, ...) /* {{{ */
2000-
{
2001-
va_list files;
2002-
int i;
2003-
zend_file_handle *file_handle;
2004-
zend_result ret = SUCCESS;
2005-
2006-
va_start(files, file_count);
2007-
for (i = 0; i < file_count; i++) {
2008-
file_handle = va_arg(files, zend_file_handle *);
2009-
if (!file_handle) {
2010-
continue;
2011-
}
2012-
if (ret == FAILURE) {
2013-
continue;
2014-
}
2015-
ret = zend_execute_script(type, retval, file_handle);
2016-
}
2017-
va_end(files);
2018-
2019-
return ret;
2020-
}
2021-
/* }}} */
2022-
20231999
#define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
20242000

20252001
ZEND_API char *zend_make_compiled_string_description(const char *name) /* {{{ */

‎Zend/zend_compile.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,6 @@ ZEND_API zend_op_array *compile_filename(int type, zend_string *filename);
962962
ZEND_API zend_op_array *zend_compile_ast(zend_ast *ast, int type, zend_string *filename);
963963
ZEND_API zend_ast *zend_compile_string_to_ast(
964964
zend_string *code, struct _zend_arena **ast_arena, zend_string *filename);
965-
ZEND_API zend_result zend_execute_scripts(int type, zval *retval, int file_count, ...);
966965
ZEND_API zend_result zend_execute_script(int type, zval *retval, zend_file_handle *file_handle);
967966
ZEND_API zend_result open_file_for_scanning(zend_file_handle *file_handle);
968967
ZEND_API void init_op_array(zend_op_array *op_array, zend_function_type type, int initial_ops_size);

‎ext/readline/readline_cli.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static int readline_shell_run(void) /* {{{ */
607607
zend_file_handle prepend_file;
608608

609609
zend_stream_init_filename(&prepend_file, PG(auto_prepend_file));
610-
zend_execute_scripts(ZEND_REQUIRE, NULL, 1, &prepend_file);
610+
zend_execute_script(ZEND_REQUIRE, NULL, &prepend_file);
611611
zend_destroy_file_handle(&prepend_file);
612612
}
613613

‎main/main.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,7 @@ PHPAPI bool php_execute_script_ex(zend_file_handle *primary_file, zval *retval)
25532553
}
25542554

25552555
/* Only lookup the real file path and add it to the included_files list if already opened
2556-
* otherwise it will get opened and added to the included_files list in zend_execute_scripts
2556+
* otherwise it will get opened and added to the included_files list in zend_execute_script
25572557
*/
25582558
if (primary_file->filename &&
25592559
!zend_string_equals_literal(primary_file->filename, "Standard input code") &&
@@ -2654,7 +2654,7 @@ PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval *ret)
26542654
php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
26552655
VCWD_CHDIR_FILE(ZSTR_VAL(primary_file->filename));
26562656
}
2657-
zend_execute_scripts(ZEND_REQUIRE, ret, 1, primary_file);
2657+
zend_execute_script(ZEND_REQUIRE, ret, primary_file);
26582658
} zend_end_try();
26592659

26602660
if (old_cwd[0] != '\0') {

‎sapi/apache2handler/sapi_apache2.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ zend_first_try {
714714
if (!parent_req) {
715715
php_execute_script(&zfd);
716716
} else {
717-
zend_execute_scripts(ZEND_INCLUDE, NULL, 1, &zfd);
717+
zend_execute_script(ZEND_INCLUDE, NULL, &zfd);
718718
}
719719
zend_destroy_file_handle(&zfd);
720720

0 commit comments

Comments
 (0)