fix and check bounds reading packets #40
Merged
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.
A lot of "slice bounds out of range" panics are occurring at https://github.com/ccding/go-stun/blob/master/stun/packet.go#L58
https://sentry.syncthing.net/share/issue/6d20d6707bfd4880a1ed8d1205f94d1d/
https://sentry.syncthing.net/share/issue/0c228b7490c84d82a7c6357bde37028c/
Two example bounds: [24:3] and [24:1]. Looks like the decoded
uint16 length
is overflowing when addingpos+4
.Looking at the code there's a few issues:
uint16
isn't ok, it might be max(uint16)+20 according to spec. I don't understand the need to do the iteration withuint16
, but I kept it just in case - removing the header from the slice before taking the length.