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
This commit is contained in:
parent
fa33ce986c
commit
2b2a2fd479
@ -11,13 +11,15 @@ import (
|
|||||||
"git.sr.ht/~emersion/soju/xirc"
|
"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) {
|
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
|
var hour, minute, second int
|
||||||
_, err := fmt.Sscanf(line, "[%02d:%02d:%02d] ", &hour, &minute, &second)
|
_, 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)
|
return nil, time.Time{}, fmt.Errorf("malformed timestamp prefix: %v", err)
|
||||||
}
|
}
|
||||||
line = line[11:]
|
line = line[timestampPrefixLen:]
|
||||||
|
|
||||||
var cmd string
|
var cmd string
|
||||||
var prefix *irc.Prefix
|
var prefix *irc.Prefix
|
||||||
|
Loading…
Reference in New Issue
Block a user