From 03b22b08f42f39e3513c33460c16871005a8f395 Mon Sep 17 00:00:00 2001 From: Andy Walker Date: Thu, 30 Jul 2015 12:58:23 -0400 Subject: [PATCH] Report on unterminated CTCP messages A bug was discovered where, under certain circumstances that are still being researched, the library would panic on a message that started with \0x01, but did not end with it. This would cause the re-slice to panic, because the library assumes a terminating index >0, effectively introducing the possibility of msg = msg[1:0]. Since this violates the CTCP spec, it is an error, and should be logged, along with the complete, escaped message. --- irc_callback.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/irc_callback.go b/irc_callback.go index d7abf74..7da4226 100644 --- a/irc_callback.go +++ b/irc_callback.go @@ -80,8 +80,10 @@ func (irc *Connection) RunCallbacks(event *Event) { if event.Code == "PRIVMSG" && len(msg) > 2 && msg[0] == '\x01' { event.Code = "CTCP" //Unknown CTCP - if i := strings.LastIndex(msg, "\x01"); i > -1 { + if i := strings.LastIndex(msg, "\x01"); i > 0 { msg = msg[1:i] + } else { + irc.Log.Printf("Invalid CTCP Message: %s\n", strconv.Quote(msg)) } if msg == "VERSION" {