Skip to content

Commit e9c0296

Browse files
committed
Fix GH-18112: NULL access with preloading and INI option
Preloading shutdown calls request shutdown which will deactivate the virtual cwd state. However, further startup code still assumes the state that was set by virtual_cwd_startup(). So we need to reactivate it manually. Creating a test was a bit difficult because the INI setting I wanted to test this with is overridden by the test runner apparently. To reproduce the issue, create an empty file test.php and execute this in a ZTS build: `php -d opcache.preload=./ext/opcache/tests/preload_class_alias_2.inc -d "error_log=" -d "allow_url_include=1" test.php` Closes GH-18117.
1 parent d9329b1 commit e9c0296

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ PHP NEWS
3434
. Fixed bug GH-17989 (mb_output_handler crash with unset
3535
http_output_conv_mimetypes). (nielsdos)
3636

37+
- Opcache:
38+
. Fixed bug GH-18112 (NULL access with preloading and INI option). (nielsdos)
39+
3740
- SPL:
3841
. Fixed bug GH-18018 (RC1 data returned from offsetGet causes UAF in
3942
ArrayObject). (nielsdos)

ext/opcache/ZendAccelerator.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4662,6 +4662,11 @@ static zend_result accel_finish_startup_preload(bool in_child)
46624662
EG(class_table) = NULL;
46634663
EG(function_table) = NULL;
46644664
PG(report_memleaks) = orig_report_memleaks;
4665+
#ifdef ZTS
4666+
/* Reset the virtual CWD state back to the original state created by virtual_cwd_startup().
4667+
* This is necessary because the normal startup code assumes the CWD state is active. */
4668+
virtual_cwd_activate();
4669+
#endif
46654670
} else {
46664671
zend_shared_alloc_unlock();
46674672
ret = FAILURE;

0 commit comments

Comments
 (0)