Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix and check bounds reading packets #40

Merged
merged 1 commit into from
Apr 12, 2021
Merged

Conversation

imsodin
Copy link
Contributor

@imsodin imsodin commented Mar 14, 2021

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 adding pos+4.

Looking at the code there's a few issues:

  • The condition on the iteration is wrong: The ranges later on can exceed the packet length.
  • The header length is 20 bytes, not sure where the 24 in code comes from?
  • Converting the length to uint16 isn't ok, it might be max(uint16)+20 according to spec. I don't understand the need to do the iteration with uint16, but I kept it just in case - removing the header from the slice before taking the length.
  • The overflow: Added a condition.

@codecov
Copy link

codecov bot commented Mar 14, 2021

Codecov Report

Merging #40 (230614f) into master (3a7a6d9) will increase coverage by 0.34%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #40      +/-   ##
==========================================
+ Coverage   22.18%   22.53%   +0.34%     
==========================================
  Files          11       11              
  Lines         320      324       +4     
==========================================
+ Hits           71       73       +2     
- Misses        244      245       +1     
- Partials        5        6       +1     
Impacted Files Coverage Δ
stun/packet.go 64.28% <57.14%> (-1.10%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a7a6d9...230614f. Read the comment docs.

@imsodin
Copy link
Contributor Author

imsodin commented Apr 11, 2021

@ccding Can you please have a look at this?

@ccding
Copy link
Owner

ccding commented Apr 12, 2021

LGTM

Thanks @imsodin

@ccding ccding merged commit 4e5e57c into ccding:master Apr 12, 2021
@imsodin imsodin deleted the fix-bounds branch April 12, 2021 22:04
@imsodin
Copy link
Contributor Author

imsodin commented Apr 13, 2021

Great, thanks for merging. Could you add a tag/make a release so we can ship this please?

@ccding
Copy link
Owner

ccding commented Apr 13, 2021

@imsodin done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants