channeldb/addr: validate ip before writing

This commit is contained in:
Johan T. Halseth 2019-01-17 14:11:56 +01:00
parent 6f605b2de2
commit 02b7bb356a
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -3,6 +3,7 @@ package channeldb
import (
"encoding/binary"
"errors"
"fmt"
"io"
"net"
@ -43,6 +44,10 @@ func encodeTCPAddr(w io.Writer, addr *net.TCPAddr) error {
ip = addr.IP.To16()
}
if ip == nil {
return fmt.Errorf("unable to encode IP %v", addr.IP)
}
if _, err := w.Write([]byte{addrType}); err != nil {
return err
}