CFPropertyList: fix out-of-bounds reads and an invalid free#52
Open
DTW-Thalion wants to merge 1 commit into
Open
CFPropertyList: fix out-of-bounds reads and an invalid free#52DTW-Thalion wants to merge 1 commit into
DTW-Thalion wants to merge 1 commit into
Conversation
The OpenStep property-list parser scans a UTF-16 buffer that is not NUL-
terminated (limit = buffer + count), yet several loops advance the cursor
and then dereference it without checking the limit:
* CFPlistStringSkipWhitespace() ran its "//" and "/* */" comment loops
with "do { cursor++; ch = *cursor; } while (ch)", relying on a
terminator that does not exist, and read one past the end after
advancing for whitespace and the leading '/';
* CFOpenStepPlistParseString() read one past the end after a backslash
escape and while scanning an unquoted string;
* CFOpenStepPlistParseObject() read *cursor when testing for the closing
'}' / ')' of a dictionary or array;
* CFOpenStepPlistParseData() read one past the end while collecting hex
bytes.
A property list larger than the 1024-character internal buffer is decoded
into a separately allocated buffer, so these are real out-of-bounds heap
reads (AddressSanitizer: heap-buffer-overflow in
CFPlistStringSkipWhitespace for a "//" comment with no trailing newline).
Add a small CFPlistStringPeek() helper that returns 0 at or past the end
of the buffer and use it for every unguarded read, so the scans stop at
the end of the data instead of running past it.
Also fix the cleanup of that separately allocated buffer: it was freed
only on the failure path, and it freed "tmp" -- which
GSUnicodeFromEncoding had advanced to the end of the buffer -- rather than
the allocation base "start". Free "start" on every path (the parser
copies anything it keeps).
Adds regression tests for a large string and a comment-only list.
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.
The OpenStep property-list parser scans a UTF-16 buffer that is not NUL-
terminated (limit = buffer + count), yet several loops advance the cursor
and then dereference it without checking the limit:
with "do { cursor++; ch = *cursor; } while (ch)", relying on a
terminator that does not exist, and read one past the end after
advancing for whitespace and the leading '/';
escape and while scanning an unquoted string;
'}' / ')' of a dictionary or array;
bytes.
A property list larger than the 1024-character internal buffer is decoded
into a separately allocated buffer, so these are real out-of-bounds heap
reads (AddressSanitizer: heap-buffer-overflow in
CFPlistStringSkipWhitespace for a "//" comment with no trailing newline).
Add a small CFPlistStringPeek() helper that returns 0 at or past the end
of the buffer and use it for every unguarded read, so the scans stop at
the end of the data instead of running past it.
Also fix the cleanup of that separately allocated buffer: it was freed
only on the failure path, and it freed "tmp" -- which
GSUnicodeFromEncoding had advanced to the end of the buffer -- rather than
the allocation base "start". Free "start" on every path (the parser
copies anything it keeps).
Adds regression tests for a large string and a comment-only list.