Fix panic: Return error before incrementing Reader's index (Reader.i) #20
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 thatret
isErr(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.