msgstore/znclog: fix error message

err may be nil.

Fixes: 2b2a2fd479 ("msgstore/znclog: fix panic on malformed input line")
This commit is contained in:
Simon Ser 2023-05-23 23:11:05 +02:00
parent 2b2a2fd479
commit 40a40566f4
1 changed files with 3 additions and 1 deletions

View File

@ -16,8 +16,10 @@ 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 || len(line) < timestampPrefixLen {
if err != nil {
return nil, time.Time{}, fmt.Errorf("malformed timestamp prefix: %v", err)
} else if len(line) < timestampPrefixLen {
return nil, time.Time{}, fmt.Errorf("malformed timestamp prefix: too short")
}
line = line[timestampPrefixLen:]