Skip to content

Commit 16bfab8

Browse files
authored
check type assertion in geoip enrichers (#3040)
1 parent 7d6514c commit 16bfab8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pkg/parser/enrich_geoip.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ func IpToRange(field string, p *types.Event, plog *log.Entry) (map[string]string
2929
return nil, nil
3030
}
3131

32-
record := r.(*net.IPNet)
32+
record, ok := r.(*net.IPNet)
33+
34+
if !ok {
35+
return nil, nil
36+
}
3337

3438
ret := make(map[string]string)
3539
ret["SourceRange"] = record.String()
@@ -49,7 +53,11 @@ func GeoIpASN(field string, p *types.Event, plog *log.Entry) (map[string]string,
4953
return nil, nil //nolint:nilerr
5054
}
5155

52-
record := r.(*geoip2.ASN)
56+
record, ok := r.(*geoip2.ASN)
57+
58+
if !ok {
59+
return nil, nil
60+
}
5361

5462
ret := make(map[string]string)
5563

@@ -74,7 +82,12 @@ func GeoIpCity(field string, p *types.Event, plog *log.Entry) (map[string]string
7482
return nil, nil //nolint:nilerr
7583
}
7684

77-
record := r.(*geoip2.City)
85+
record, ok := r.(*geoip2.City)
86+
87+
if !ok {
88+
return nil, nil
89+
}
90+
7891
ret := make(map[string]string)
7992

8093
if record.Country.IsoCode != "" {

0 commit comments

Comments
 (0)