Skip to content

Fix out-of-bounds token read on trailing address delimiters#60

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/addr-token-oob-read
Open

Fix out-of-bounds token read on trailing address delimiters#60
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/addr-token-oob-read

Conversation

@iliaal
Copy link
Copy Markdown

@iliaal iliaal commented Jun 7, 2026

In parse_address_tokens(), a run of trailing ',' or ';' delimiters can advance start_tok to toks->ntokens. The addr-spec branch then reads toks->tokens[start_tok].token with start_tok equal to ntokens, one element past the ecalloc'd token array. This strips the enclosing <> only when the address span is non-empty (a_count > 0), which also keeps the index in bounds; the route-addr branch is already guarded by its own i < ntokens check. Applied to both the .re source and the generated .c.

Reproducer: mailparse_rfc822_parse_addresses("a@b,,").

When the delimiter-skip loop in parse_address_tokens() advances start_tok
to exactly toks->ntokens (an address followed by one or more trailing ','
or ';'), the addr-spec branch read toks->tokens[start_tok].token with
start_tok == ntokens, one element past the ecalloc'd token array.
mailparse_rfc822_parse_addresses("a@b,,") triggers it.

Only strip the enclosing <> when the address span is non-empty
(a_count > 0), which also guarantees a_start < ntokens. The route-addr
branch is already guarded by its i < ntokens entry condition.

Change applied to both the .re source and the generated .c.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant