Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ext/standard/head.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,23 @@ static zend_result php_head_parse_cookie_options_array(HashTable *options, zend_
if (zend_string_equals_literal_ci(key, "expires")) {
*expires = zval_get_long(value);
} else if (zend_string_equals_literal_ci(key, "path")) {
if (*path) {
zend_string_release(*path);
}
*path = zval_get_string(value);
} else if (zend_string_equals_literal_ci(key, "domain")) {
if (*domain) {
zend_string_release(*domain);
}
*domain = zval_get_string(value);
} else if (zend_string_equals_literal_ci(key, "secure")) {
*secure = zval_is_true(value);
} else if (zend_string_equals_literal_ci(key, "httponly")) {
*httponly = zval_is_true(value);
} else if (zend_string_equals_literal_ci(key, "samesite")) {
if (*samesite) {
zend_string_release(*samesite);
}
*samesite = zval_get_string(value);
} else {
zend_value_error("%s(): option \"%s\" is invalid", get_active_function_name(), ZSTR_VAL(key));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
setcookie() does not leak when an option array has case-variant duplicate keys
--FILE--
<?php
$base = memory_get_usage();
for ($i = 0; $i < 5000; $i++) {
@setcookie('name', 'value', ['path' => '/aaaaaaaaaaaaaaaa' . $i, 'Path' => '/bbbbbbbbbbbbbbbb' . $i]);
header_remove();
}
// Each duplicate-key call leaked the first path string before the fix,
// growing usage by tens of bytes per iteration (hundreds of KB here).
var_dump(memory_get_usage() - $base < 50000);
?>
--EXPECT--
bool(true)
Loading