diff --git a/php_mailparse_rfc822.c b/php_mailparse_rfc822.c index 28a001a..903d810 100644 --- a/php_mailparse_rfc822.c +++ b/php_mailparse_rfc822.c @@ -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--; } diff --git a/php_mailparse_rfc822.re b/php_mailparse_rfc822.re index 98699ac..c22dabb 100644 --- a/php_mailparse_rfc822.re +++ b/php_mailparse_rfc822.re @@ -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--; } diff --git a/tests/addr_trailing_delim_oob.phpt b/tests/addr_trailing_delim_oob.phpt new file mode 100644 index 0000000..1502ac0 --- /dev/null +++ b/tests/addr_trailing_delim_oob.phpt @@ -0,0 +1,16 @@ +--TEST-- +Trailing delimiters in an address list do not read past the token array +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(3) "a@b" +bool(true) +done