lib-mail: message-parser - Fix out-of-bounds read on empty preamble#297
Open
nishat-06 wants to merge 1 commit into
Open
lib-mail: message-parser - Fix out-of-bounds read on empty preamble#297nishat-06 wants to merge 1 commit into
nishat-06 wants to merge 1 commit into
Conversation
Contributor
|
Thank you, we'll take a look. |
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.
Re-parsing a multipart message from cached parts with
MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS, on a message whose MIMEpart has an empty preamble (the boundary is the first thing in the body):
preparsed_parse_prologue_more()scans backwards from the boundary'strailing CRLF for the newline that precedes
--boundary. With no preamblethe boundary sits at the very start of the prologue block, so the scan runs
off the front and exits with
cur == block_r->data - 1.data[-1]happensto be the
\nending the multipart part header, so the--check passes ondata[0]/data[1]andblock_r->size = cur - block_r->dataunderflows to anear-
SIZE_MAXvalue. The prologue block is then handed to the consumer withthat size, which over-reads (the panic above is a consumer appending it).
Reachable via
message_parser_init_from_parts()when a caller re-parses amessage against its cached
message_parttree and asks for multipart blocks.Handle the no-preamble case explicitly: when the backward scan finds no
newline, confirm the block starts with
--and return an empty prologue.Regression test added to test-message-parser.c.