Skip to content

Commit d840200

Browse files
committed
Fix GH-16229: Address overflowed in mb_send_mail when empty string
1 parent 331da7e commit d840200

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ext/mbstring/mbstring.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4179,7 +4179,8 @@ PHP_FUNCTION(mb_send_mail)
41794179
#define PHP_MBSTR_MAIL_MIME_HEADER2 "Content-Type: text/plain"
41804180
#define PHP_MBSTR_MAIL_MIME_HEADER3 "; charset="
41814181
#define PHP_MBSTR_MAIL_MIME_HEADER4 "Content-Transfer-Encoding: "
4182-
if (str_headers != NULL) {
4182+
4183+
if (str_headers != NULL && ZSTR_LEN(str_headers) > 0) {
41834184
p = ZSTR_VAL(str_headers);
41844185
n = ZSTR_LEN(str_headers);
41854186
mbfl_memory_device_strncat(&device, p, n);

ext/mbstring/tests/gh16229.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-16229 (Address overflowed in ext/mbstring/mbstring.c:4613 #16229)
3+
--EXTENSIONS--
4+
mbstring
5+
--INI--
6+
sendmail_path={MAIL:{PWD}/mb_send_mail_gh16229.eml}
7+
mail.add_x_header=off
8+
--SKIPIF--
9+
<?php
10+
if (!function_exists("mb_send_mail") || !mb_language("japanese")) {
11+
die("skip mb_send_mail() not available");
12+
}
13+
?>
14+
--FILE--
15+
<?php
16+
try {
17+
$a = false;
18+
mb_send_mail($a,$a,$a,$a,$a);
19+
} catch (Exception $e) {
20+
}
21+
?>
22+
--CLEAN--
23+
<?php
24+
@unlink(__DIR__ . "/mb_send_mail_gh16229.eml");
25+
?>
26+
--EXPECTF--

0 commit comments

Comments
 (0)