Skip to content

Commit f128358

Browse files
committed
Fix GH-17951: memory_limit ini value not being overwritten by max_memory_limit
Make sure to always duplicate max_memory_limit ini value. Otherwise the alter ini routine may assume the value hasn't been overwritten, resulting in the user-specified value being set after the on_modify handler has run.
1 parent 43c3afe commit f128358

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static PHP_INI_MH(OnChangeMemoryLimit)
346346
}
347347

348348
zend_ini_entry *max_mem_limit_ini = zend_hash_str_find_ptr(EG(ini_directives), ZEND_STRL("max_memory_limit"));
349-
entry->value = zend_string_copy(max_mem_limit_ini->value);
349+
entry->value = zend_string_init(ZSTR_VAL(max_mem_limit_ini->value), ZSTR_LEN(max_mem_limit_ini->value), true);
350350
PG(memory_limit) = PG(max_memory_limit);
351351

352352
return SUCCESS;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-17951 Runtime Change 6
3+
--INI--
4+
memory_limit=128M
5+
max_memory_limit=512M
6+
--FILE--
7+
<?php
8+
for($i = 0; $i < 3; $i++) {
9+
ini_set('memory_limit', '1024M');
10+
echo ini_get('memory_limit');
11+
}
12+
?>
13+
--EXPECTF--
14+
Warning: Failed to set memory_limit to 1073741824 bytes. Setting to max_memory_limit instead (currently: 536870912 bytes) in %s on line %d
15+
512M
16+
Warning: Failed to set memory_limit to 1073741824 bytes. Setting to max_memory_limit instead (currently: 536870912 bytes) in %s on line %d
17+
512M
18+
Warning: Failed to set memory_limit to 1073741824 bytes. Setting to max_memory_limit instead (currently: 536870912 bytes) in %s on line %d
19+
512M

0 commit comments

Comments
 (0)