mit-dci / lit

Lightning Network node software
MIT License
551 stars 119 forks source link

Fix segfault by checking for nil messages #299

Closed metalicjames closed 6 years ago

metalicjames commented 6 years ago

If a node sends a message we don't understand Lit crashes with the following error:

2018/07/27 23:56:52.876702 connected to /Satoshi:0.12.1/
2018/07/27 23:56:52.876724 Handshake with 2001:41d0:2:1c08:: failed. Moving on.
2018/07/27 23:56:52.876744 Remote node version: 1117c too old, disconnecting.
2018/07/27 23:56:52.876762 Couldn't establish connection with node. Proceeding to the next one
2018/07/27 23:56:52.876784 Attempting connection to node at [2001:470:1f06:15b4::2]:18333
2018/07/27 23:56:52.904094 wrote 134 byte version message to [2001:470:1f06:15b4::2]:18333
2018/07/27 23:56:52.934858 got 126 byte response 7f1101000d0400000000000084e95b5b00000000000000000000000026010184407fb1ce0000000000006598acd20d04000000000000000000000000000000000000000000000000052f082b23b5a87e102f5361746f7368693a302e31362e302f25b0140001
 command: version
2018/07/27 23:56:52.934907 connected to /Satoshi:0.16.0/
2018/07/27 23:56:52.934927 remote reports version 1117f (dec 70015)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x778420]

goroutine 56 [running]:
github.com/mit-dci/lit/uspv.(*SPVCon).incomingMessageHandler(0xc420068380)
    /home/james/workspace/go/src/github.com/mit-dci/lit/uspv/msghandler.go:62 +0x160
created by github.com/mit-dci/lit/uspv.(*SPVCon).Connect
    /home/james/workspace/go/src/github.com/mit-dci/lit/uspv/init.go:231 +0x2ed

This PR checks for nil and allows Lit to continue running.