Skip to content

Commit 7bc4bd0

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Moved NEWS entry Fixed possible crashes, because of inconsistent PCRE cache and opcache SHM reset
2 parents 2244a7d + bb7ecb8 commit 7bc4bd0

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static zend_always_inline zend_string *accel_find_interned_string(zend_string *s
438438
}
439439

440440
if (!ZCG(counted)) {
441-
if (accel_activate_add() == FAILURE) {
441+
if (!ZCG(accelerator_enabled) || accel_activate_add() == FAILURE) {
442442
return str;
443443
}
444444
ZCG(counted) = 1;
@@ -1154,7 +1154,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
11541154
cwd_len = ZSTR_LEN(cwd_str);
11551155
if (ZCG(cwd_check)) {
11561156
ZCG(cwd_check) = 0;
1157-
if ((ZCG(counted) || ZCSG(accelerator_enabled))) {
1157+
if (ZCG(accelerator_enabled)) {
11581158

11591159
zend_string *str = accel_find_interned_string(cwd_str);
11601160
if (!str) {
@@ -1194,7 +1194,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
11941194

11951195
if (ZCG(include_path_check)) {
11961196
ZCG(include_path_check) = 0;
1197-
if ((ZCG(counted) || ZCSG(accelerator_enabled))) {
1197+
if (ZCG(accelerator_enabled)) {
11981198

11991199
zend_string *str = accel_find_interned_string(ZCG(include_path));
12001200
if (!str) {
@@ -1277,7 +1277,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool f
12771277
zend_string *realpath;
12781278
zend_persistent_script *persistent_script;
12791279

1280-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
1280+
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
12811281
return FAILURE;
12821282
}
12831283

@@ -1881,7 +1881,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
18811881
return accelerator_orig_compile_file(file_handle, type);
18821882
} else if (file_cache_only) {
18831883
return file_cache_compile_file(file_handle, type);
1884-
} else if ((!ZCG(counted) && !ZCSG(accelerator_enabled)) ||
1884+
} else if (!ZCG(accelerator_enabled) ||
18851885
(ZCSG(restart_in_progress) && accel_restart_is_active())) {
18861886
if (ZCG(accel_directives).file_cache) {
18871887
return file_cache_compile_file(file_handle, type);
@@ -2168,10 +2168,8 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl
21682168
/* zend_resolve_path() replacement for PHP 5.3 and above */
21692169
static zend_string* persistent_zend_resolve_path(const char *filename, size_t filename_len)
21702170
{
2171-
if (ZCG(enabled) && accel_startup_ok &&
2172-
!file_cache_only &&
2173-
(ZCG(counted) || ZCSG(accelerator_enabled)) &&
2174-
!ZCSG(restart_in_progress)) {
2171+
if (!file_cache_only &&
2172+
ZCG(accelerator_enabled)) {
21752173

21762174
/* check if callback is called from include_once or it's a main request */
21772175
if ((!EG(current_execute_data) &&
@@ -2313,6 +2311,7 @@ int accel_activate(INIT_FUNC_ARGS)
23132311
zend_alter_ini_entry_chars(key, "0", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_RUNTIME);
23142312
zend_string_release_ex(key, 0);
23152313
zend_accel_error(ACCEL_LOG_WARNING, "Can't cache files in chroot() directory with too big inode");
2314+
ZCG(accelerator_enabled) = 0;
23162315
return SUCCESS;
23172316
}
23182317
}
@@ -2374,12 +2373,15 @@ int accel_activate(INIT_FUNC_ARGS)
23742373
}
23752374
accel_restart_leave();
23762375
}
2377-
} else {
2376+
}
2377+
if (!ZCG(pcre_reseted)) {
23782378
reset_pcre = 1;
23792379
}
23802380
zend_shared_alloc_unlock();
23812381
}
23822382

2383+
ZCG(accelerator_enabled) = ZCSG(accelerator_enabled);
2384+
23832385
SHM_PROTECT();
23842386
HANDLE_UNBLOCK_INTERRUPTIONS();
23852387

@@ -2391,8 +2393,10 @@ int accel_activate(INIT_FUNC_ARGS)
23912393
realpath_cache_clean();
23922394

23932395
accel_reset_pcre_cache();
2396+
ZCG(pcre_reseted) = 0;
23942397
} else if (reset_pcre) {
23952398
accel_reset_pcre_cache();
2399+
ZCG(pcre_reseted) = 1;
23962400
}
23972401

23982402
if (ZCSG(preload_script)) {

ext/opcache/ZendAccelerator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ typedef struct _zend_accel_globals {
191191
int counted; /* the process uses shared memory */
192192
zend_bool enabled;
193193
zend_bool locked; /* thread obtained exclusive lock */
194+
zend_bool accelerator_enabled; /* accelerator enabled for current request */
195+
zend_bool pcre_reseted;
194196
HashTable bind_hash; /* prototype and zval lookup table */
195197
zend_accel_directives accel_directives;
196198
zend_string *cwd; /* current working directory or NULL */

ext/opcache/zend_accelerator_module.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,7 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
433433
{
434434
php_info_print_table_start();
435435

436-
if (ZCG(enabled) && accel_startup_ok &&
437-
((ZCG(counted) || ZCSG(accelerator_enabled)) || file_cache_only)
438-
) {
436+
if (ZCG(accelerator_enabled) || file_cache_only) {
439437
php_info_print_table_row(2, "Opcode Caching", "Up and Running");
440438
} else {
441439
php_info_print_table_row(2, "Opcode Caching", "Disabled");
@@ -535,7 +533,7 @@ static int accelerator_get_scripts(zval *return_value)
535533
struct timeval exec_time;
536534
struct timeval fetch_time;
537535

538-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
536+
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
539537
return 0;
540538
}
541539

@@ -597,7 +595,7 @@ static ZEND_FUNCTION(opcache_get_status)
597595
array_init(return_value);
598596

599597
/* Trivia */
600-
add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled)));
598+
add_assoc_bool(return_value, "opcache_enabled", ZCG(accelerator_enabled));
601599

602600
if (ZCG(accel_directives).file_cache) {
603601
add_assoc_string(return_value, "file_cache", ZCG(accel_directives).file_cache);
@@ -879,7 +877,7 @@ static ZEND_FUNCTION(opcache_is_script_cached)
879877
RETURN_FALSE;
880878
}
881879

882-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
880+
if (!ZCG(accelerator_enabled)) {
883881
RETURN_FALSE;
884882
}
885883

0 commit comments

Comments
 (0)