appsec: avoid nil dereference (#2773)

This commit is contained in:
mmetc 2024-01-23 09:32:41 +01:00 committed by GitHub
parent 84606eb207
commit 4b8e6cd780
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -329,7 +329,7 @@ func NewParsedRequestFromRequest(r *http.Request, logger *logrus.Entry) (ParsedR
return ParsedRequest{}, fmt.Errorf("unable to parse url '%s': %s", clientURI, err) return ParsedRequest{}, fmt.Errorf("unable to parse url '%s': %s", clientURI, err)
} }
remoteAddrNormalized := "" var remoteAddrNormalized string
host, _, err := net.SplitHostPort(r.RemoteAddr) host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil { if err != nil {
log.Errorf("Invalid appsec remote IP source %v: %s", r.RemoteAddr, err.Error()) log.Errorf("Invalid appsec remote IP source %v: %s", r.RemoteAddr, err.Error())
@ -337,7 +337,7 @@ func NewParsedRequestFromRequest(r *http.Request, logger *logrus.Entry) (ParsedR
} else { } else {
ip := net.ParseIP(host) ip := net.ParseIP(host)
if ip == nil { if ip == nil {
log.Errorf("Invalid appsec remote IP address source %v: %s", r.RemoteAddr, err.Error()) log.Errorf("Invalid appsec remote IP address source %v", r.RemoteAddr)
remoteAddrNormalized = r.RemoteAddr remoteAddrNormalized = r.RemoteAddr
} else { } else {
remoteAddrNormalized = ip.String() remoteAddrNormalized = ip.String()