fiorix / go-smpp

SMPP 3.4 Protocol for the Go programming language
MIT License
218 stars 135 forks source link

handle pdu if nil returned #83

Closed YektaLeblebici closed 3 years ago

YektaLeblebici commented 5 years ago

In some cases [1] r.cl.Read() returns a nil interface without any errors, leading to panics when the p.Header() (when p == nil) is called.

This change adds a simple check for nil values.

Example:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x5c5389]

goroutine 7 [running]:
redacted/vendor/github.com/fiorix/go-smpp/smpp.(*Receiver).handlePDU(0xc0000ec180)
        /home/yekta/.go/src/redacted/vendor/github.com/fiorix/go-smpp/smpp/receiver.go:176 +0x1f9
created by redacted/vendor/github.com/fiorix/go-smpp/smpp.(*Receiver).bindFunc
        /home/yekta/.go/src/redacted/vendor/github.com/fiorix/go-smpp/smpp/receiver.go:132 +0x344
exit status 2

[1] For example, when the connection is abruptly closed by the server.

orn1983 commented 4 years ago

Why is this not merged yet? If you have a receiver with a bound handler, this panic gets triggered upon a reset connection. The same does not apply to a bound transceiver, but I haven't looked into why.

This seems like a simple enough fix to merge.

Edit: Maybe because there is a deeper underlying bug? For instance, why does r.cl.Read() not return an error on a reset connection?