Skip to content
Open
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
2 changes: 1 addition & 1 deletion php_mailparse_rfc822.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ static void parse_address_tokens(php_rfc822_tokenized_t *toks,
a_count = i - start_tok;
/* if an address is enclosed in <>, leave them out of the the
* address value that we return */
if (toks->tokens[a_start].token == '<') {
if (a_count > 0 && toks->tokens[a_start].token == '<') {
a_start++;
a_count--;
}
Expand Down
2 changes: 1 addition & 1 deletion php_mailparse_rfc822.re
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ mailbox: /* addr-spec / phrase route-addr */
a_count = i - start_tok;
/* if an address is enclosed in <>, leave them out of the the
* address value that we return */
if (toks->tokens[a_start].token == '<') {
if (a_count > 0 && toks->tokens[a_start].token == '<') {
a_start++;
a_count--;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/addr_trailing_delim_oob.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Trailing delimiters in an address list do not read past the token array
--SKIPIF--
<?php if (!extension_loaded("mailparse")) print "skip"; ?>
--FILE--
<?php
$r = mailparse_rfc822_parse_addresses("a@b,,");
var_dump($r[0]['address']);
$r = mailparse_rfc822_parse_addresses("grp: a@b,,");
var_dump($r[0]['is_group']);
echo "done\n";
?>
--EXPECT--
string(3) "a@b"
bool(true)
done
Loading