[Explain] s02 can cause panic if empty (#2486)
* Add parsers length check as it can panic is enrich is empty * Lets get smarter and loop backwards to find last successful stage * Shorten code --------- Co-authored-by: Thibault "bui" Koechlin <thibault@crowdsec.net>
This commit is contained in:
parent
95ed308207
commit
b8e6bd8c9a
1 changed files with 8 additions and 3 deletions
|
@ -321,9 +321,14 @@ func LoadParserDump(filepath string) (*ParserResults, error) {
|
|||
stages = append(stages, k)
|
||||
}
|
||||
sort.Strings(stages)
|
||||
/*the very last one is set to 'success' which is just a bool indicating if the line was successfully parsed*/
|
||||
lastStage := stages[len(stages)-2]
|
||||
|
||||
var lastStage string
|
||||
//Loop over stages to find last successful one with at least one parser
|
||||
for i := len(stages) - 2; i >= 0; i-- {
|
||||
if len(pdump[stages[i]]) != 0 {
|
||||
lastStage = stages[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
parsers := make([]string, 0, len(pdump[lastStage]))
|
||||
for k := range pdump[lastStage] {
|
||||
parsers = append(parsers, k)
|
||||
|
|
Loading…
Reference in a new issue