Fix out-of-bounds read in RFC822 group/route-addr address parsing#64
Closed
iliaal wants to merge 1 commit into
Closed
Fix out-of-bounds read in RFC822 group/route-addr address parsing#64iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
Contributor
Author
|
Superseded by #69, reopened from the fork (iliaal/pecl-mail-mailparse). Branch should not have been pushed to php/ directly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
mailparse_rfc822_parse_addresses()reads (and can write) one element past the end of the parsed address array on crafted input such as<>:<or:;:<.The parser runs two passes: one with a NULL output to count addresses and size the array, then one to fill it. A group whose inner mailbox is an unterminated route-addr (
<with no closing>) advances the token cursor past the group's;, so the two passes disagree on how many slotsiaddrreaches. The fill pass then indexesaddrs->addrs[iaddr]atiaddr == naddrs, one past theecalloc'd array.This is the sibling of the addr-spec case fixed by the recent
a_count > 0guard; the group/route-addr path indexing the address array itself was never bounds-checked.Fix
Bound every fill-pass write to
addrs->addrs[iaddr]byiaddr < addrs->naddrs(the count established by the first pass). On valid input the passes agree and the guard never fires; on the desyncing malformed input it drops the stray write instead of running off the array, and frees the orphanedaddress_valueso nothing leaks.Both
php_mailparse_rfc822.reand the generatedphp_mailparse_rfc822.ccarry the change, matching how this file is maintained.