Skip to content

Commit 580b9a4

Browse files
committed
Merge branch 'PHP-8.5'
2 parents e861608 + 9de37a3 commit 580b9a4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ext/standard/mail.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ PHPAPI zend_string *php_mail_build_headers(HashTable *headers)
218218
ZEND_HASH_FOREACH_KEY_VAL(headers, idx, key, val) {
219219
if (!key) {
220220
zend_type_error("Header name cannot be numeric, " ZEND_LONG_FMT " given", idx);
221-
break;
221+
smart_str_free(&s);
222+
return NULL;
222223
}
223224
ZVAL_DEREF(val);
224225
/* https://tools.ietf.org/html/rfc2822#section-3.6 */
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-20776: mail() memory leak when header array contains numeric keys
3+
--FILE--
4+
<?php
5+
6+
$subject = $message = "";
7+
8+
try {
9+
var_dump(mail($to, $subject, $message, ['RandomHeader' => 'Value', 5 => 'invalid key']));
10+
} catch (Throwable $e) {
11+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
12+
}
13+
?>
14+
--EXPECT--
15+
TypeError: Header name cannot be numeric, 5 given

0 commit comments

Comments
 (0)