[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
|
@ -321,9 +321,14 @@ func LoadParserDump(filepath string) (*ParserResults, error) {
|
||||||
stages = append(stages, k)
|
stages = append(stages, k)
|
||||||
}
|
}
|
||||||
sort.Strings(stages)
|
sort.Strings(stages)
|
||||||
/*the very last one is set to 'success' which is just a bool indicating if the line was successfully parsed*/
|
var lastStage string
|
||||||
lastStage := stages[len(stages)-2]
|
//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]))
|
parsers := make([]string, 0, len(pdump[lastStage]))
|
||||||
for k := range pdump[lastStage] {
|
for k := range pdump[lastStage] {
|
||||||
parsers = append(parsers, k)
|
parsers = append(parsers, k)
|
||||||
|
|
Loading…
Reference in a new issue