From 2b2a2fd4798d7ba1defa410146fdad9bb163199f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 23 May 2023 23:08:44 +0200 Subject: [PATCH] msgstore/znclog: fix panic on malformed input line If the line is "[01:02:03]" without a trailing space, we trip on a "slice bounds out of range" panic. Closes: https://todo.sr.ht/~emersion/soju/214 --- msgstore/znclog/reader.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/msgstore/znclog/reader.go b/msgstore/znclog/reader.go index 4edbca3..43cb5fd 100644 --- a/msgstore/znclog/reader.go +++ b/msgstore/znclog/reader.go @@ -11,13 +11,15 @@ import ( "git.sr.ht/~emersion/soju/xirc" ) +var timestampPrefixLen = len("[01:02:03] ") + func UnmarshalLine(line string, user *database.User, network *database.Network, entity string, ref time.Time, events bool) (*irc.Message, time.Time, error) { var hour, minute, second int _, err := fmt.Sscanf(line, "[%02d:%02d:%02d] ", &hour, &minute, &second) - if err != nil { + if err != nil || len(line) < timestampPrefixLen { return nil, time.Time{}, fmt.Errorf("malformed timestamp prefix: %v", err) } - line = line[11:] + line = line[timestampPrefixLen:] var cmd string var prefix *irc.Prefix