diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 528dd353..e84d43b1 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -1319,7 +1319,21 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) { l.fail("error receiving fee update: %v", err) return } + case *lnwire.Error: + // Error received from remote, MUST fail channel, but should + // only print the contents of the error message if all + // characters are printable ASCII. + errMsg := "non-ascii data" + if isASCII(msg.Data) { + errMsg = string(msg.Data) + } + l.fail("ChannelPoint(%v): recieved error from peer: %v", + l.channel.ChannelPoint(), errMsg) + default: + log.Warnf("ChannelPoint(%v): received unknown message of type %T", + l.channel.ChannelPoint(), msg) } + } // ackDownStreamPackets is responsible for removing htlcs from a link's @@ -2407,3 +2421,16 @@ func (l *channelLink) tracef(format string, a ...interface{}) { msg := fmt.Sprintf(format, a...) log.Tracef("ChannelLink(%s) %s", l.ShortChanID(), msg) } + +// isASCII is a helper method that checks whether all bytes in `data` would be +// printable ASCII characters if interpreted as a string. +func isASCII(data []byte) bool { + isASCII := true + for _, c := range data { + if c < 32 || c > 126 { + isASCII = false + break + } + } + return isASCII +}