Skip to content

Commit d23cd35

Browse files
committed
Fix #79665: ini_get() and opcache_get_configuration() inconsistency
Overriding the given INI values in modifier callbacks is not possible, so instead of enforcing "normalized" internal values, we just reject the attempted changes.
1 parent 72d1c50 commit d23cd35

File tree

3 files changed

+38
-47
lines changed

3 files changed

+38
-47
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ PHP NEWS
9595
. Fixed bug #78654 (Incorrectly computed opcache checksum on files with
9696
non-ascii characters). (mhagstrand)
9797
. Fixed bug #76535 (Opcache does not replay compile-time warnings). (Nikita)
98+
. Fixed bug #79665 (ini_get() and opcache_get_configuration() inconsistency).
99+
(cmb)
98100

99101
- PCRE:
100102
. Don't ignore invalid escape sequences. (sjon)

ext/opcache/tests/bug79665.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #79665 (ini_get() and opcache_get_configuration() may be inconsistent)
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/skipif.inc';
6+
?>
7+
--INI--
8+
opcache.max_wasted_percentage=60
9+
opcache.memory_consumption=7
10+
opcache.max_accelerated_files=10
11+
--FILE--
12+
<?php
13+
$config = opcache_get_configuration();
14+
var_dump(ini_get('opcache.max_wasted_percentage'));
15+
var_dump($config['directives']['opcache.max_wasted_percentage']);
16+
var_dump(ini_get('opcache.memory_consumption'));
17+
var_dump($config['directives']['opcache.memory_consumption']);
18+
var_dump(ini_get('opcache.max_accelerated_files'));
19+
var_dump($config['directives']['opcache.max_accelerated_files']);
20+
?>
21+
--EXPECT--
22+
string(1) "5"
23+
float(0.05)
24+
string(3) "128"
25+
int(134217728)
26+
string(5) "10000"
27+
int(10000)

ext/opcache/zend_accelerator_module.c

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,8 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption)
6767
zend_long memsize = atoi(ZSTR_VAL(new_value));
6868
/* sanity check we must use at least 8 MB */
6969
if (memsize < 8) {
70-
const char *new_new_value = "8";
71-
zend_ini_entry *ini_entry;
72-
73-
memsize = 8;
7470
zend_accel_error(ACCEL_LOG_WARNING, "opcache.memory_consumption is set below the required 8MB.\n");
75-
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use the minimal 8MB configuration.\n");
76-
77-
if ((ini_entry = zend_hash_str_find_ptr(EG(ini_directives),
78-
"opcache.memory_consumption",
79-
sizeof("opcache.memory_consumption")-1)) == NULL) {
80-
return FAILURE;
81-
}
82-
83-
ini_entry->value = zend_string_init_interned(new_new_value, 1, 1);
71+
return FAILURE;
8472
}
8573
if (UNEXPECTED(memsize > ZEND_ULONG_MAX / (1024 * 1024))) {
8674
*p = ZEND_ULONG_MAX;
@@ -95,29 +83,13 @@ static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
9583
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
9684
zend_long size = atoi(ZSTR_VAL(new_value));
9785
/* sanity check we must use a value between MIN_ACCEL_FILES and MAX_ACCEL_FILES */
98-
99-
if (size < MIN_ACCEL_FILES || size > MAX_ACCEL_FILES) {
100-
const char *new_new_value;
101-
zend_ini_entry *ini_entry;
102-
103-
if (size < MIN_ACCEL_FILES) {
104-
size = MIN_ACCEL_FILES;
105-
new_new_value = TOKENTOSTR(MIN_ACCEL_FILES);
106-
zend_accel_error(ACCEL_LOG_WARNING, "opcache.max_accelerated_files is set below the required minimum (%d).\n", MIN_ACCEL_FILES);
107-
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use the minimal configuration.\n");
108-
}
109-
if (size > MAX_ACCEL_FILES) {
110-
size = MAX_ACCEL_FILES;
111-
new_new_value = TOKENTOSTR(MAX_ACCEL_FILES);
112-
zend_accel_error(ACCEL_LOG_WARNING, "opcache.max_accelerated_files is set above the limit (%d).\n", MAX_ACCEL_FILES);
113-
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use the maximal configuration.\n");
114-
}
115-
if ((ini_entry = zend_hash_str_find_ptr(EG(ini_directives),
116-
"opcache.max_accelerated_files",
117-
sizeof("opcache.max_accelerated_files")-1)) == NULL) {
118-
return FAILURE;
119-
}
120-
ini_entry->value = zend_string_init_interned(new_new_value, strlen(new_new_value), 1);
86+
if (size < MIN_ACCEL_FILES) {
87+
zend_accel_error(ACCEL_LOG_WARNING, "opcache.max_accelerated_files is set below the required minimum (%d).\n", MIN_ACCEL_FILES);
88+
return FAILURE;
89+
}
90+
if (size > MAX_ACCEL_FILES) {
91+
zend_accel_error(ACCEL_LOG_WARNING, "opcache.max_accelerated_files is set above the limit (%d).\n", MAX_ACCEL_FILES);
92+
return FAILURE;
12193
}
12294
*p = size;
12395
return SUCCESS;
@@ -129,18 +101,8 @@ static ZEND_INI_MH(OnUpdateMaxWastedPercentage)
129101
zend_long percentage = atoi(ZSTR_VAL(new_value));
130102

131103
if (percentage <= 0 || percentage > 50) {
132-
const char *new_new_value = "5";
133-
zend_ini_entry *ini_entry;
134-
135-
percentage = 5;
136104
zend_accel_error(ACCEL_LOG_WARNING, "opcache.max_wasted_percentage must be set between 1 and 50.\n");
137-
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use 5%%.\n");
138-
if ((ini_entry = zend_hash_str_find_ptr(EG(ini_directives),
139-
"opcache.max_wasted_percentage",
140-
sizeof("opcache.max_wasted_percentage")-1)) == NULL) {
141-
return FAILURE;
142-
}
143-
ini_entry->value = zend_string_init_interned(new_new_value, strlen(new_new_value), 1);
105+
return FAILURE;
144106
}
145107
*p = (double)percentage / 100.0;
146108
return SUCCESS;

0 commit comments

Comments
 (0)