Skip to content

Commit ab9d121

Browse files
committed
Fix access to uninitialized variables in preload_load()
preload_load() reads EG(class_table) and EG(function_table), but these may not be initialized. Move these accesses out of preload_load(). Closes GH-20081
1 parent 059f9f7 commit ab9d121

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PHP NEWS
1111
. Fixed bug GH-19974 (fpm_status_export_to_zval segfault for parallel
1212
execution). (Jakub Zelenka, txuna)
1313

14+
- Opcache:
15+
. Fixed bug GH-20081 (access to uninitialized vars in preload_load()).
16+
(Arnaud)
17+
1418
- Random:
1519
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)
1620

ext/opcache/ZendAccelerator.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4345,15 +4345,6 @@ static void preload_load(void)
43454345
}
43464346
}
43474347

4348-
if (EG(zend_constants)) {
4349-
EG(persistent_constants_count) = EG(zend_constants)->nNumUsed;
4350-
}
4351-
if (EG(function_table)) {
4352-
EG(persistent_functions_count) = EG(function_table)->nNumUsed;
4353-
}
4354-
if (EG(class_table)) {
4355-
EG(persistent_classes_count) = EG(class_table)->nNumUsed;
4356-
}
43574348
if (CG(map_ptr_last) != ZCSG(map_ptr_last)) {
43584349
size_t old_map_ptr_last = CG(map_ptr_last);
43594350
CG(map_ptr_last) = ZCSG(map_ptr_last);
@@ -4589,6 +4580,12 @@ static zend_result accel_preload(const char *config, bool in_child)
45894580

45904581
preload_load();
45914582

4583+
/* Update persistent counts, as shutdown will discard anything past
4584+
* that, and these tables are aliases to global ones at this point. */
4585+
EG(persistent_functions_count) = EG(function_table)->nNumUsed;
4586+
EG(persistent_classes_count) = EG(class_table)->nNumUsed;
4587+
EG(persistent_constants_count) = EG(zend_constants)->nNumUsed;
4588+
45924589
/* Store individual scripts with unlinked classes */
45934590
HANDLE_BLOCK_INTERRUPTIONS();
45944591
SHM_UNPROTECT();

0 commit comments

Comments
 (0)