Skip to content

Commit 5c4d125

Browse files
committed
Fixed possible crashes, because of inconsistent PCRE cache and opcache SHM reset
1 parent 704a0ab commit 5c4d125

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
@@ -12,6 +12,10 @@ PHP NEWS
1212
- JSON:
1313
. Fixed bug #77843 (Use after free with json serializer). (Nikita)
1414

15+
- Opcache:
16+
. Fixed possible crashes, because of inconsistent PCRE cache and opcache
17+
SHM reset. (Alexey Kalinin, Dmitry)
18+
1519
- PDO_MySQL:
1620
. Fixed bug #77944 (Wrong meta pdo_type for bigint on LLP64). (cmb)
1721

ext/opcache/ZendAccelerator.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static zend_string *accel_find_interned_string(zend_string *str)
412412
}
413413

414414
if (!ZCG(counted)) {
415-
if (accel_activate_add() == FAILURE) {
415+
if (!ZCG(accelerator_enabled) || accel_activate_add() == FAILURE) {
416416
return str;
417417
}
418418
ZCG(counted) = 1;
@@ -1070,7 +1070,7 @@ char *accel_make_persistent_key(const char *path, int path_length, int *key_len)
10701070
cwd_len = ZSTR_LEN(cwd_str);
10711071
if (ZCG(cwd_check)) {
10721072
ZCG(cwd_check) = 0;
1073-
if ((ZCG(counted) || ZCSG(accelerator_enabled))) {
1073+
if (ZCG(accelerator_enabled)) {
10741074

10751075
zend_string *str = accel_find_interned_string(cwd_str);
10761076
if (!str) {
@@ -1110,7 +1110,7 @@ char *accel_make_persistent_key(const char *path, int path_length, int *key_len)
11101110

11111111
if (ZCG(include_path_check)) {
11121112
ZCG(include_path_check) = 0;
1113-
if ((ZCG(counted) || ZCSG(accelerator_enabled))) {
1113+
if (ZCG(accelerator_enabled)) {
11141114

11151115
zend_string *str = accel_find_interned_string(ZCG(include_path));
11161116
if (!str) {
@@ -1193,7 +1193,7 @@ int zend_accel_invalidate(const char *filename, int filename_len, zend_bool forc
11931193
zend_string *realpath;
11941194
zend_persistent_script *persistent_script;
11951195

1196-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
1196+
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
11971197
return FAILURE;
11981198
}
11991199

@@ -1764,7 +1764,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
17641764
} else if (file_cache_only) {
17651765
return file_cache_compile_file(file_handle, type);
17661766
#endif
1767-
} else if ((!ZCG(counted) && !ZCSG(accelerator_enabled)) ||
1767+
} else if (!ZCG(accelerator_enabled) ||
17681768
(ZCSG(restart_in_progress) && accel_restart_is_active())) {
17691769
#ifdef HAVE_OPCACHE_FILE_CACHE
17701770
if (ZCG(accel_directives).file_cache) {
@@ -2059,12 +2059,11 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl
20592059
/* zend_resolve_path() replacement for PHP 5.3 and above */
20602060
static zend_string* persistent_zend_resolve_path(const char *filename, int filename_len)
20612061
{
2062-
if (ZCG(enabled) && accel_startup_ok &&
2062+
if (
20632063
#ifdef HAVE_OPCACHE_FILE_CACHE
20642064
!file_cache_only &&
20652065
#endif
2066-
(ZCG(counted) || ZCSG(accelerator_enabled)) &&
2067-
!ZCSG(restart_in_progress)) {
2066+
ZCG(accelerator_enabled)) {
20682067

20692068
/* check if callback is called from include_once or it's a main request */
20702069
if ((!EG(current_execute_data) &&
@@ -2213,6 +2212,7 @@ static void accel_activate(void)
22132212
zend_alter_ini_entry_chars(key, "0", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_RUNTIME);
22142213
zend_string_release(key);
22152214
zend_accel_error(ACCEL_LOG_WARNING, "Can't cache files in chroot() directory with too big inode");
2215+
ZCG(accelerator_enabled) = 0;
22162216
return;
22172217
}
22182218
}
@@ -2270,12 +2270,15 @@ static void accel_activate(void)
22702270
}
22712271
accel_restart_leave();
22722272
}
2273-
} else {
2273+
}
2274+
if (!ZCG(pcre_reseted)) {
22742275
reset_pcre = 1;
22752276
}
22762277
zend_shared_alloc_unlock();
22772278
}
22782279

2280+
ZCG(accelerator_enabled) = ZCSG(accelerator_enabled);
2281+
22792282
SHM_PROTECT();
22802283
HANDLE_UNBLOCK_INTERRUPTIONS();
22812284

@@ -2287,8 +2290,10 @@ static void accel_activate(void)
22872290
realpath_cache_clean();
22882291

22892292
accel_reset_pcre_cache();
2293+
ZCG(pcre_reseted) = 0;
22902294
} else if (reset_pcre) {
22912295
accel_reset_pcre_cache();
2296+
ZCG(pcre_reseted) = 1;
22922297
}
22932298
}
22942299

@@ -2316,10 +2321,6 @@ static void accel_deactivate(void)
23162321
zend_string_release(ZCG(cwd));
23172322
ZCG(cwd) = NULL;
23182323
}
2319-
2320-
if (!ZCG(enabled) || !accel_startup_ok) {
2321-
return;
2322-
}
23232324
}
23242325

23252326
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
@@ -196,6 +196,8 @@ typedef struct _zend_accel_globals {
196196
int counted; /* the process uses shared memory */
197197
zend_bool enabled;
198198
zend_bool locked; /* thread obtained exclusive lock */
199+
zend_bool accelerator_enabled; /* accelerator enabled for current request */
200+
zend_bool pcre_reseted;
199201
HashTable bind_hash; /* prototype and zval lookup table */
200202
zend_accel_directives accel_directives;
201203
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
@@ -439,11 +439,11 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
439439
{
440440
php_info_print_table_start();
441441

442-
if (ZCG(enabled) && accel_startup_ok &&
442+
if (
443443
#ifdef HAVE_OPCACHE_FILE_CACHE
444-
((ZCG(counted) || ZCSG(accelerator_enabled)) || file_cache_only)
444+
(ZCG(accelerator_enabled) || file_cache_only)
445445
#else
446-
(ZCG(counted) || ZCSG(accelerator_enabled))
446+
(ZCG(accelerator_enabled))
447447
#endif
448448
) {
449449
php_info_print_table_row(2, "Opcode Caching", "Up and Running");
@@ -547,7 +547,7 @@ static int accelerator_get_scripts(zval *return_value)
547547
struct timeval exec_time;
548548
struct timeval fetch_time;
549549

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

@@ -609,7 +609,7 @@ static ZEND_FUNCTION(opcache_get_status)
609609
array_init(return_value);
610610

611611
/* Trivia */
612-
add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled)));
612+
add_assoc_bool(return_value, "opcache_enabled", ZCG(accelerator_enabled));
613613

614614
#ifdef HAVE_OPCACHE_FILE_CACHE
615615
if (ZCG(accel_directives).file_cache) {
@@ -807,7 +807,7 @@ static ZEND_FUNCTION(opcache_compile_file)
807807
return;
808808
}
809809

810-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
810+
if (!ZCG(accelerator_enabled)) {
811811
zend_error(E_NOTICE, ACCELERATOR_PRODUCT_NAME " seems to be disabled, can't compile file");
812812
RETURN_FALSE;
813813
}
@@ -846,7 +846,7 @@ static ZEND_FUNCTION(opcache_is_script_cached)
846846
RETURN_FALSE;
847847
}
848848

849-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
849+
if (!ZCG(accelerator_enabled)) {
850850
RETURN_FALSE;
851851
}
852852

0 commit comments

Comments
 (0)