Skip to content

Commit 79c5b32

Browse files
committed
Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
We should dereference the values, otherwise references don't work. Closes GH-10991.
1 parent cf9b030 commit 79c5b32

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
- PCRE:
1515
. Fixed bug GH-10968 (Segfault in preg_replace_callback_array()). (ilutov)
1616

17+
- Standard:
18+
. Fixed bug GH-10990 (mail() throws TypeError after iterating over
19+
$additional_headers array by reference). (nielsdos)
20+
1721
13 Apr 2023, PHP 8.1.18
1822

1923
- Core:

ext/standard/mail.c

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *v
136136
zend_type_error("Header \"%s\" must only contain numeric keys, \"%s\" found", ZSTR_VAL(key), ZSTR_VAL(tmp_key));
137137
break;
138138
}
139+
ZVAL_DEREF(tmp_val);
139140
if (Z_TYPE_P(tmp_val) != IS_STRING) {
140141
zend_type_error("Header \"%s\" must only contain values of type string, %s found", ZSTR_VAL(key), zend_zval_type_name(tmp_val));
141142
break;
@@ -157,6 +158,7 @@ PHPAPI zend_string *php_mail_build_headers(HashTable *headers)
157158
zend_type_error("Header name cannot be numeric, " ZEND_LONG_FMT " given", idx);
158159
break;
159160
}
161+
ZVAL_DEREF(val);
160162
/* https://tools.ietf.org/html/rfc2822#section-3.6 */
161163
if (zend_string_equals_literal_ci(key, "orig-date")) {
162164
PHP_MAIL_BUILD_HEADER_CHECK("orig-date", s, key, val);

ext/standard/tests/mail/gh10990.phpt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-10990 (mail() throws TypeError after iterating over $additional_headers array by reference)
3+
--INI--
4+
sendmail_path=rubbish 2>/dev/null
5+
--SKIPIF--
6+
<?php
7+
if(substr(PHP_OS, 0, 3) == "WIN")
8+
die("skip Won't run on Windows");
9+
?>
10+
--FILE--
11+
<?php
12+
13+
$headers = ['From' => &$from];
14+
var_dump(mail('[email protected]', 'Test', 'Test', $headers));
15+
?>
16+
--EXPECT--
17+
bool(false)

0 commit comments

Comments
 (0)