Fix panic: Return error before incrementing Reader's index (Reader.i)#20
Merged
briansmith merged 1 commit intobriansmith:masterfrom Jun 21, 2018
Merged
Conversation
briansmith
approved these changes
Jun 21, 2018
Owner
briansmith
left a comment
There was a problem hiding this comment.
Thanks. I can't believe we didn't write it this way originally. I wonder what I was thinking.
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.
I'm reporting this here (with a fix) because of
https://github.com/briansmith/untrusted/blob/3c842f49cb51fcc72b3656ad063e024d4b725115/README.md#bug-reporting
Proof of Concept code:
crashes with:
There are actually combination of two errors:
First, there's my mistake: Proof of concept code on line
doesn't check for error as it should and continues with
Secondly, Untrusted's error: untrusted's
Reader::skip_and_get_input()function doesn't return error before increasing the index pointing to a buffer:untrusted/src/untrusted.rs
Lines 316 to 324 in 44384f8
here line 318 calculated the new index value, then lines 319-321 try to construct new
Input, but since this can fail there's a possibility thatretisErr(EndOfInput). However, this error is not returned when it happens and code continues to line 322 where Reader's index (self.i) is increased and thenskip_and_get_input()is done and it returnsErr(EndOfInput).This allows the case where Reader's index can point to outside of buffer thus panicing later.