~emersion/soju

2b2a2fd4798d7ba1defa410146fdad9bb163199f — Simon Ser 11 months ago fa33ce9
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
1 files changed, 4 insertions(+), 2 deletions(-)

M msgstore/znclog/reader.go
M msgstore/znclog/reader.go => msgstore/znclog/reader.go +4 -2
@@ 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