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.
This commit is contained in:
Andy Walker 2015-07-30 12:58:23 -04:00
parent 6112236593
commit 03b22b08f4

View File

@ -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" {