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 panic in avp.DecodeFromBytes #96

Merged
merged 8 commits into from
Oct 29, 2018
Merged

fix panic in avp.DecodeFromBytes #96

merged 8 commits into from
Oct 29, 2018

Conversation

0rac1e
Copy link
Contributor

@0rac1e 0rac1e commented Sep 17, 2018

in some cases method crashes with panic. Extra length check added.

panic: runtime error: slice bounds out of range

goroutine 27 [running]:
github.com/fiorix/go-diameter/diam.(*AVP).DecodeFromBytes(0xc003185d40, 0xc002f862a8, 0x28, 0x158, 0x4, 0xc0000a4050, 0x3, 0x800000c002686480)
/go/src/github.com/fiorix/go-diameter/diam/avp.go:74 +0x5b1
github.com/fiorix/go-diameter/diam.DecodeAVP(0xc002f862a8, 0x28, 0x158, 0x4, 0xc0000a4050, 0xc002686480, 0x8, 0x10)
/go/src/github.com/fiorix/go-diameter/diam/avp.go:45 +0x74
github.com/fiorix/go-diameter/diam.DecodeGrouped(0xc002f861f0, 0xe0, 0x210, 0x4, 0xc0000a4050, 0xc000389400, 0x0, 0x0)
/go/src/github.com/fiorix/go-diameter/diam/group.go:29 +0xfc
github.com/fiorix/go-diameter/diam.(*AVP).DecodeFromBytes(0xc003185b00, 0xc002f861e4, 0xec, 0x21c, 0x4, 0xc0000

in some cases method crashes with panic. Extra length check added.

panic: runtime error: slice bounds out of range

goroutine 27 [running]:
github.com/fiorix/go-diameter/diam.(*AVP).DecodeFromBytes(0xc003185d40, 0xc002f862a8, 0x28, 0x158, 0x4, 0xc0000a4050, 0x3, 0x800000c002686480)
        /go/src/github.com/fiorix/go-diameter/diam/avp.go:74 +0x5b1
github.com/fiorix/go-diameter/diam.DecodeAVP(0xc002f862a8, 0x28, 0x158, 0x4, 0xc0000a4050, 0xc002686480, 0x8, 0x10)
        /go/src/github.com/fiorix/go-diameter/diam/avp.go:45 +0x74
github.com/fiorix/go-diameter/diam.DecodeGrouped(0xc002f861f0, 0xe0, 0x210, 0x4, 0xc0000a4050, 0xc000389400, 0x0, 0x0)
        /go/src/github.com/fiorix/go-diameter/diam/group.go:29 +0xfc
github.com/fiorix/go-diameter/diam.(*AVP).DecodeFromBytes(0xc003185b00, 0xc002f861e4, 0xec, 0x21c, 0x4, 0xc0000
@fiorix
Copy link
Owner

fiorix commented Sep 24, 2018

I'm surprised this check isn't elsewhere. Perhaps there's something else going on here. Where does 12 come from?

Tests are failing, cannot proceed before tests pass.

@aaronchar
Copy link

For what it's worth I have had this happen as well, interested to see what this would do

@0rac1e
Copy link
Contributor Author

0rac1e commented Sep 24, 2018

panic occurs on line 71/74 avp.go
payload = data[12:]/payload = data[8:] - 12 comes from here
when
a.Length = int(uint24to32(data[5:8])) // returns 1 in my case

I think data given to DecodeFromBytes method is not valid.

* in some cases method crashes with panic. Extra length check added.
not really sure, should it be 12 (payload = data[12:])

* Avp Length is already an int, no need for cast.

panic: runtime error: slice bounds out of range
goroutine 27 [running]:
github.com/fiorix/go-diameter/diam.(*AVP).DecodeFromBytes(0xc003185d40, 0xc002f862a8, 0x28, 0x158, 0x4, 0xc0000a4050, 0x3, 0x800000c002686480)
        /go/src/github.com/fiorix/go-diameter/diam/avp.go:74 +0x5b1
github.com/fiorix/go-diameter/diam.DecodeAVP(0xc002f862a8, 0x28, 0x158, 0x4, 0xc0000a4050, 0xc002686480, 0x8, 0x10)
        /go/src/github.com/fiorix/go-diameter/diam/avp.go:45 +0x74
github.com/fiorix/go-diameter/diam.DecodeGrouped(0xc002f861f0, 0xe0, 0x210, 0x4, 0xc0000a4050, 0xc000389400, 0x0, 0x0)
        /go/src/github.com/fiorix/go-diameter/diam/group.go:29 +0xfc
github.com/fiorix/go-diameter/diam.(*AVP).DecodeFromBytes(0xc003185b00, 0xc002f861e4, 0xec, 0x21c, 0x4, 0xc0000
Note that, in order to choose Go 1.10, you must use go: "1.10" (a string), not go: 1.10 (a float). Using a float results in the use of Go 1.1. - https://docs.travis-ci.com/user/languages/go/
@0rac1e 0rac1e force-pushed the master branch 2 times, most recently from 541b376 to cdebf4a Compare September 25, 2018 05:39
* Avp Length is already an int, no need for cast.

* in some cases method crashes with panic. Extra length check added.
not really sure, should it be 12 (payload = data[12:])

panic: runtime error: slice bounds out of range
goroutine 27 [running]:
github.com/fiorix/go-diameter/diam.(*AVP).DecodeFromBytes(0xc003185d40, 0xc002f862a8, 0x28, 0x158, 0x4, 0xc0000a4050, 0x3, 0x800000c002686480)
        /go/src/github.com/fiorix/go-diameter/diam/avp.go:74 +0x5b1
github.com/fiorix/go-diameter/diam.DecodeAVP(0xc002f862a8, 0x28, 0x158, 0x4, 0xc0000a4050, 0xc002686480, 0x8, 0x10)
        /go/src/github.com/fiorix/go-diameter/diam/avp.go:45 +0x74
github.com/fiorix/go-diameter/diam.DecodeGrouped(0xc002f861f0, 0xe0, 0x210, 0x4, 0xc0000a4050, 0xc000389400, 0x0, 0x0)
        /go/src/github.com/fiorix/go-diameter/diam/group.go:29 +0xfc
github.com/fiorix/go-diameter/diam.(*AVP).DecodeFromBytes(0xc003185b00, 0xc002f861e4, 0xec, 0x21c, 0x4, 0xc0000
@0rac1e 0rac1e force-pushed the master branch 2 times, most recently from a2dd034 to cb0c531 Compare September 25, 2018 08:42
@0rac1e 0rac1e force-pushed the master branch 2 times, most recently from 74be173 to 33fa2fe Compare October 2, 2018 06:36
simple channel receive instead of select with a single check
TestHandleCER_VS_AuthSCTP was lower case
@fiorix fiorix merged commit abaf0a5 into fiorix:master Oct 29, 2018
@fiorix
Copy link
Owner

fiorix commented Oct 29, 2018

Good catch, thanks!

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.

None yet

3 participants