Skip to content

Commit 53c1b48

Browse files
dstogovcmb69
authored andcommitted
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fixed possible crashes, because of inconsistent PCRE cache and opcache SHM reset
1 parent 40235e7 commit 53c1b48

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
- JSON:
1717
. Fixed bug #77843 (Use after free with json serializer). (Nikita)
1818

19+
- Opcache:
20+
. Fixed possible crashes, because of inconsistent PCRE cache and opcache
21+
SHM reset. (Alexey Kalinin, Dmitry)
22+
1923
- PDO_MySQL:
2024
. Fixed bug #77944 (Wrong meta pdo_type for bigint on LLP64). (cmb)
2125

ext/opcache/ZendAccelerator.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static zend_always_inline zend_string *accel_find_interned_string(zend_string *s
431431
}
432432

433433
if (!ZCG(counted)) {
434-
if (accel_activate_add() == FAILURE) {
434+
if (!ZCG(accelerator_enabled) || accel_activate_add() == FAILURE) {
435435
return str;
436436
}
437437
ZCG(counted) = 1;
@@ -1164,7 +1164,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
11641164
cwd_len = ZSTR_LEN(cwd_str);
11651165
if (ZCG(cwd_check)) {
11661166
ZCG(cwd_check) = 0;
1167-
if ((ZCG(counted) || ZCSG(accelerator_enabled))) {
1167+
if (ZCG(accelerator_enabled)) {
11681168

11691169
zend_string *str = accel_find_interned_string(cwd_str);
11701170
if (!str) {
@@ -1204,7 +1204,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
12041204

12051205
if (ZCG(include_path_check)) {
12061206
ZCG(include_path_check) = 0;
1207-
if ((ZCG(counted) || ZCSG(accelerator_enabled))) {
1207+
if (ZCG(accelerator_enabled)) {
12081208

12091209
zend_string *str = accel_find_interned_string(ZCG(include_path));
12101210
if (!str) {
@@ -1287,7 +1287,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool f
12871287
zend_string *realpath;
12881288
zend_persistent_script *persistent_script;
12891289

1290-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
1290+
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
12911291
return FAILURE;
12921292
}
12931293

@@ -1910,7 +1910,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
19101910
} else if (file_cache_only) {
19111911
return file_cache_compile_file(file_handle, type);
19121912
#endif
1913-
} else if ((!ZCG(counted) && !ZCSG(accelerator_enabled)) ||
1913+
} else if (!ZCG(accelerator_enabled) ||
19141914
(ZCSG(restart_in_progress) && accel_restart_is_active())) {
19151915
#ifdef HAVE_OPCACHE_FILE_CACHE
19161916
if (ZCG(accel_directives).file_cache) {
@@ -2205,12 +2205,11 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl
22052205
/* zend_resolve_path() replacement for PHP 5.3 and above */
22062206
static zend_string* persistent_zend_resolve_path(const char *filename, size_t filename_len)
22072207
{
2208-
if (ZCG(enabled) && accel_startup_ok &&
2208+
if (
22092209
#ifdef HAVE_OPCACHE_FILE_CACHE
22102210
!file_cache_only &&
22112211
#endif
2212-
(ZCG(counted) || ZCSG(accelerator_enabled)) &&
2213-
!ZCSG(restart_in_progress)) {
2212+
ZCG(accelerator_enabled)) {
22142213

22152214
/* check if callback is called from include_once or it's a main request */
22162215
if ((!EG(current_execute_data) &&
@@ -2359,6 +2358,7 @@ static void accel_activate(void)
23592358
zend_alter_ini_entry_chars(key, "0", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_RUNTIME);
23602359
zend_string_release_ex(key, 0);
23612360
zend_accel_error(ACCEL_LOG_WARNING, "Can't cache files in chroot() directory with too big inode");
2361+
ZCG(accelerator_enabled) = 0;
23622362
return;
23632363
}
23642364
}
@@ -2416,12 +2416,15 @@ static void accel_activate(void)
24162416
}
24172417
accel_restart_leave();
24182418
}
2419-
} else {
2419+
}
2420+
if (!ZCG(pcre_reseted)) {
24202421
reset_pcre = 1;
24212422
}
24222423
zend_shared_alloc_unlock();
24232424
}
24242425

2426+
ZCG(accelerator_enabled) = ZCSG(accelerator_enabled);
2427+
24252428
SHM_PROTECT();
24262429
HANDLE_UNBLOCK_INTERRUPTIONS();
24272430

@@ -2433,8 +2436,10 @@ static void accel_activate(void)
24332436
realpath_cache_clean();
24342437

24352438
accel_reset_pcre_cache();
2439+
ZCG(pcre_reseted) = 0;
24362440
} else if (reset_pcre) {
24372441
accel_reset_pcre_cache();
2442+
ZCG(pcre_reseted) = 1;
24382443
}
24392444
}
24402445

@@ -2462,10 +2467,6 @@ static void accel_deactivate(void)
24622467
zend_string_release_ex(ZCG(cwd), 0);
24632468
ZCG(cwd) = NULL;
24642469
}
2465-
2466-
if (!ZCG(enabled) || !accel_startup_ok) {
2467-
return;
2468-
}
24692470
}
24702471

24712472
static int accelerator_remove_cb(zend_extension *element1, zend_extension *element2)

ext/opcache/ZendAccelerator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ typedef struct _zend_accel_globals {
195195
int counted; /* the process uses shared memory */
196196
zend_bool enabled;
197197
zend_bool locked; /* thread obtained exclusive lock */
198+
zend_bool accelerator_enabled; /* accelerator enabled for current request */
199+
zend_bool pcre_reseted;
198200
HashTable bind_hash; /* prototype and zval lookup table */
199201
zend_accel_directives accel_directives;
200202
zend_string *cwd; /* current working directory or NULL */

ext/opcache/zend_accelerator_module.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,11 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
438438
{
439439
php_info_print_table_start();
440440

441-
if (ZCG(enabled) && accel_startup_ok &&
441+
if (
442442
#ifdef HAVE_OPCACHE_FILE_CACHE
443-
((ZCG(counted) || ZCSG(accelerator_enabled)) || file_cache_only)
443+
(ZCG(accelerator_enabled) || file_cache_only)
444444
#else
445-
(ZCG(counted) || ZCSG(accelerator_enabled))
445+
(ZCG(accelerator_enabled))
446446
#endif
447447
) {
448448
php_info_print_table_row(2, "Opcode Caching", "Up and Running");
@@ -546,7 +546,7 @@ static int accelerator_get_scripts(zval *return_value)
546546
struct timeval exec_time;
547547
struct timeval fetch_time;
548548

549-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
549+
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
550550
return 0;
551551
}
552552

@@ -608,7 +608,7 @@ static ZEND_FUNCTION(opcache_get_status)
608608
array_init(return_value);
609609

610610
/* Trivia */
611-
add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled)));
611+
add_assoc_bool(return_value, "opcache_enabled", ZCG(accelerator_enabled));
612612

613613
#ifdef HAVE_OPCACHE_FILE_CACHE
614614
if (ZCG(accel_directives).file_cache) {
@@ -805,7 +805,7 @@ static ZEND_FUNCTION(opcache_compile_file)
805805
return;
806806
}
807807

808-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
808+
if (!ZCG(accelerator_enabled)) {
809809
zend_error(E_NOTICE, ACCELERATOR_PRODUCT_NAME " seems to be disabled, can't compile file");
810810
RETURN_FALSE;
811811
}
@@ -844,7 +844,7 @@ static ZEND_FUNCTION(opcache_is_script_cached)
844844
RETURN_FALSE;
845845
}
846846

847-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
847+
if (!ZCG(accelerator_enabled)) {
848848
RETURN_FALSE;
849849
}
850850

0 commit comments

Comments
 (0)