From 74c37c2fc9d1b20d7074906cdf60c34848831c1e Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 11 Dec 2022 22:56:14 +0100 Subject: [PATCH] Avoid out of bounds exception if checksum is ok but data is crap --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index c68cfbc..421a06c 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" "flag" + "fmt" "io" "log" "os" @@ -155,6 +156,11 @@ func treatLine(line []byte, legacyMode bool) (key string, horodate *time.Time, d fields := bytes.Fields(line) + if len(fields) < 2 { + err = fmt.Errorf("Invalid number of fields in line") + return + } + key = string(fields[0]) horodate, err = getHorodate(&fields)