pion / dtls

DTLS 1.2 Server/Client implementation for Go
https://pion.ly/
MIT License
604 stars 158 forks source link

nil pointer dereference in State.UnmarshalBinary #591

Closed 0x34d closed 7 months ago

0x34d commented 1 year ago

File : resume_test.go

func TestUnmarshalBinary(t *testing.T) {
    deserialized := &State{}
    _ = deserialized.UnmarshalBinary([]byte("\x01$"))
}

Run go test -run TestUnmarshalBinary .

Backtrace

--- FAIL: TestUnmarshalBinary (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x6be89c]

goroutine 6 [running]:
testing.tRunner.func1.2({0x72c920, 0x9d2ae0})
    /usr/lib/golang/src/testing/testing.go:1526 +0x24e
testing.tRunner.func1()
    /usr/lib/golang/src/testing/testing.go:1529 +0x39f
panic({0x72c920, 0x9d2ae0})
    /usr/lib/golang/src/runtime/panic.go:884 +0x213
github.com/pion/dtls/v2.(*State).initCipherSuite(0xc0000aa780)
    /home/0x34d/project/dtls/state.go:161 +0x3c
github.com/pion/dtls/v2.(*State).UnmarshalBinary(0x4f7214?, {0xc00001a348, 0x2, 0x2})
    /home/0x34d/project/dtls/state.go:202 +0x132
github.com/pion/dtls/v2.TestUnmarshalBinary(0x0?)
    /home/0x34d/project/dtls/resume_test.go:216 +0x50
testing.tRunner(0xc0000c89c0, 0x7b5380)
    /usr/lib/golang/src/testing/testing.go:1576 +0x10b
created by testing.(*T).Run
    /usr/lib/golang/src/testing/testing.go:1629 +0x3ea
FAIL    github.com/pion/dtls/v2 0.007s
FAIL