From 53f49f043fa3d97cb6153bab2291c197b600c518 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 25 Feb 2023 13:42:45 +0100 Subject: [PATCH] Fix GH-10692: PHP crashes on Windows when an inexistent filename is executed Fixes GH-10692 php_fopen_primary_script() does not initialize all fields of zend_file_handle. So when it fails and when fastcgi is true, the zend_destroy_file_handle() function will try to free uninitialized pointers, causing a segmentation fault. Fix it by zero-initializing file handles just like the zend_stream_init_fp() counterpart does. --- main/fopen_wrappers.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 12cc9c8b10c01..efb110171b148 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -353,6 +353,8 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) size_t length; bool orig_display_errors; + memset(file_handle, 0, sizeof(zend_file_handle)); + path_info = SG(request_info).request_uri; #if HAVE_PWD_H if (PG(user_dir) && *PG(user_dir) && path_info && '/' == path_info[0] && '~' == path_info[1]) {