Skip to content

Commit

Permalink
check type assertion in geoip enrichers (#3040)
Browse files Browse the repository at this point in the history
  • Loading branch information
blotus committed May 31, 2024
1 parent 7d6514c commit 16bfab8
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pkg/parser/enrich_geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ func IpToRange(field string, p *types.Event, plog *log.Entry) (map[string]string
return nil, nil
}

record := r.(*net.IPNet)
record, ok := r.(*net.IPNet)

if !ok {
return nil, nil
}

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

record := r.(*geoip2.ASN)
record, ok := r.(*geoip2.ASN)

if !ok {
return nil, nil
}

ret := make(map[string]string)

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

record := r.(*geoip2.City)
record, ok := r.(*geoip2.City)

if !ok {
return nil, nil
}

ret := make(map[string]string)

if record.Country.IsoCode != "" {
Expand Down

0 comments on commit 16bfab8

Please sign in to comment.