Skip to content

Commit 557e70f

Browse files
committed
Alternative to phpGH-19963
1 parent 8a10141 commit 557e70f

File tree

21 files changed

+71
-46
lines changed

21 files changed

+71
-46
lines changed

Zend/zend_ini.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static zend_result zend_restore_ini_entry_cb(zend_ini_entry *ini_entry, int stag
5858
/* even if on_modify bails out, we have to continue on with restoring,
5959
since there can be allocated variables that would be freed on MM shutdown
6060
and would lead to memory corruption later ini entry is modified again */
61-
result = ini_entry->on_modify(ini_entry, ini_entry->orig_value, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage);
61+
result = ini_entry->on_modify(ini_entry, ini_entry->orig_value, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage, NULL);
6262
} zend_end_try();
6363
}
6464
if (stage == ZEND_INI_STAGE_RUNTIME && result == FAILURE) {
@@ -249,21 +249,20 @@ ZEND_API zend_result zend_register_ini_entries_ex(const zend_ini_entry_def *ini_
249249
return FAILURE;
250250
}
251251

252-
zend_string *prev_value = p->value;
253-
252+
bool modified = false;
254253
if (((default_value = zend_get_configuration_directive(p->name)) != NULL) &&
255-
(!p->on_modify || p->on_modify(p, Z_STR_P(default_value), p->mh_arg1, p->mh_arg2, p->mh_arg3, ZEND_INI_STAGE_STARTUP) == SUCCESS)) {
254+
(!p->on_modify || p->on_modify(p, Z_STR_P(default_value), p->mh_arg1, p->mh_arg2, p->mh_arg3, ZEND_INI_STAGE_STARTUP, &modified) == SUCCESS)) {
256255

257256
/* Skip assigning the value if the handler has already done so. */
258-
if (p->value == prev_value) {
257+
if (!modified) {
259258
p->value = zend_new_interned_string(zend_string_copy(Z_STR_P(default_value)));
260259
}
261260
} else {
262261
p->value = ini_entry->value ?
263262
zend_string_init_interned(ini_entry->value, ini_entry->value_length, 1) : NULL;
264263

265264
if (p->on_modify) {
266-
p->on_modify(p, p->value, p->mh_arg1, p->mh_arg2, p->mh_arg3, ZEND_INI_STAGE_STARTUP);
265+
p->on_modify(p, p->value, p->mh_arg1, p->mh_arg2, p->mh_arg3, ZEND_INI_STAGE_STARTUP, NULL);
267266
}
268267
}
269268
ini_entry++;
@@ -398,13 +397,14 @@ ZEND_API zend_result zend_alter_ini_entry_ex(zend_string *name, zend_string *new
398397
zend_string *prev_value = ini_entry->value;
399398
duplicate = zend_string_copy(new_value);
400399

400+
bool changed_by_on_modify = false;
401401
if (!ini_entry->on_modify
402-
|| ini_entry->on_modify(ini_entry, duplicate, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage) == SUCCESS) {
402+
|| ini_entry->on_modify(ini_entry, duplicate, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage, &changed_by_on_modify) == SUCCESS) {
403403
if (modified && ini_entry->orig_value != prev_value) { /* we already changed the value, free the changed value */
404404
zend_string_release(prev_value);
405405
}
406406
/* Skip assigning the value if the handler has already done so. */
407-
if (ini_entry->value == prev_value) {
407+
if (!changed_by_on_modify) {
408408
ini_entry->value = duplicate;
409409
} else {
410410
zend_string_release(duplicate);

Zend/zend_ini.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#define ZEND_INI_ALL (ZEND_INI_USER|ZEND_INI_PERDIR|ZEND_INI_SYSTEM)
2929

30-
#define ZEND_INI_MH(name) int name(zend_ini_entry *entry, zend_string *new_value, void *mh_arg1, void *mh_arg2, void *mh_arg3, int stage)
30+
#define ZEND_INI_MH(name) int name(zend_ini_entry *entry, zend_string *new_value, void *mh_arg1, void *mh_arg2, void *mh_arg3, int stage, bool *modified)
3131
#define ZEND_INI_DISP(name) ZEND_COLD void name(zend_ini_entry *ini_entry, int type)
3232

3333
typedef struct _zend_ini_entry_def {

ext/com_dotnet/com_extension.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static ZEND_INI_MH(OnAutoregisterCasesensitive)
145145
php_error_docref("com.configuration", E_WARNING, "Declaration of case-insensitive constants is no longer supported");
146146
return FAILURE;
147147
}
148-
return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
148+
return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
149149
}
150150

151151
PHP_INI_BEGIN()

ext/date/php_date.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ static PHP_INI_MH(OnUpdate_date_timezone)
541541
return FAILURE;
542542
}
543543

544-
if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) {
544+
if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified) == FAILURE) {
545545
return FAILURE;
546546
}
547547

ext/dba/dba.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ static ZEND_INI_MH(OnUpdateDefaultHandler)
363363

364364
if (!ZSTR_LEN(new_value)) {
365365
DBA_G(default_hptr) = NULL;
366-
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
366+
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
367367
}
368368

369369
for (hptr = handler; hptr->name && strcasecmp(hptr->name, ZSTR_VAL(new_value)); hptr++);
@@ -373,7 +373,7 @@ static ZEND_INI_MH(OnUpdateDefaultHandler)
373373
return FAILURE;
374374
}
375375
DBA_G(default_hptr) = hptr;
376-
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
376+
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
377377
}
378378

379379
PHP_INI_BEGIN()

ext/exif/exif.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ ZEND_INI_MH(OnUpdateEncode)
117117
}
118118
pefree((void *) return_list, 0);
119119
}
120-
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
120+
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
121121
}
122122

123123
ZEND_INI_MH(OnUpdateDecode)
@@ -132,7 +132,7 @@ ZEND_INI_MH(OnUpdateDecode)
132132
}
133133
pefree((void *) return_list, 0);
134134
}
135-
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
135+
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
136136
}
137137

138138
PHP_INI_BEGIN()

ext/iconv/iconv.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static PHP_INI_MH(OnUpdateInputEncoding)
174174
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
175175
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.input_encoding is deprecated");
176176
}
177-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
177+
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
178178
return SUCCESS;
179179
}
180180

@@ -187,7 +187,7 @@ static PHP_INI_MH(OnUpdateOutputEncoding)
187187
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
188188
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.output_encoding is deprecated");
189189
}
190-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
190+
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
191191
return SUCCESS;
192192
}
193193

@@ -200,7 +200,7 @@ static PHP_INI_MH(OnUpdateInternalEncoding)
200200
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
201201
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.internal_encoding is deprecated");
202202
}
203-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
203+
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
204204
return SUCCESS;
205205
}
206206

ext/mbstring/mbstring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ static PHP_INI_MH(OnUpdate_mbstring_internal_encoding)
825825
php_error_docref("ref.mbstring", E_DEPRECATED, "Use of mbstring.internal_encoding is deprecated");
826826
}
827827

828-
if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) {
828+
if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified) == FAILURE) {
829829
return FAILURE;
830830
}
831831

@@ -884,7 +884,7 @@ static PHP_INI_MH(OnUpdate_mbstring_encoding_translation)
884884
return FAILURE;
885885
}
886886

887-
OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
887+
OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
888888

889889
if (MBSTRG(encoding_translation)) {
890890
sapi_unregister_post_entry(php_post_entries);

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void zend_accel_schedule_restart_if_necessary(zend_accel_restart_reason reason)
264264
*/
265265
static ZEND_INI_MH(accel_include_path_on_modify)
266266
{
267-
int ret = orig_include_path_on_modify(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
267+
int ret = orig_include_path_on_modify(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
268268

269269
if (ret == SUCCESS) {
270270
ZCG(include_path) = new_value;

ext/opcache/zend_accelerator_module.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static ZEND_INI_MH(OnEnable)
157157
if (stage == ZEND_INI_STAGE_STARTUP ||
158158
stage == ZEND_INI_STAGE_SHUTDOWN ||
159159
stage == ZEND_INI_STAGE_DEACTIVATE) {
160-
return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
160+
return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
161161
} else {
162162
/* It may be only temporarily disabled */
163163
bool *p = (bool *) ZEND_INI_GET_ADDR();
@@ -192,15 +192,15 @@ static ZEND_INI_MH(OnUpdateFileCache)
192192
new_value = NULL;
193193
}
194194
}
195-
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
195+
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
196196
return SUCCESS;
197197
}
198198

199199
#ifdef HAVE_JIT
200200
static ZEND_INI_MH(OnUpdateJit)
201201
{
202202
if (zend_jit_config(new_value, stage) == SUCCESS) {
203-
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
203+
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage, modified);
204204
}
205205
return FAILURE;
206206
}

0 commit comments

Comments
 (0)