Avoid crash in PopulatePublicKey() by re-initializing the args (#8388)

This is to avoid nil pointer dereference when method by pointer
reference and method by value reference are implemented.

Fixes #8387
master
Harshavardhana 5 years ago committed by kannappanr
parent 1c90485b56
commit f16df2a4e7
  1. 17
      pkg/iam/openid/jwt.go

@ -62,14 +62,11 @@ func (r *JWKSArgs) PopulatePublicKey() error {
return err return err
} }
r.publicKeys = make(map[string]crypto.PublicKey)
for _, key := range jwk.Keys { for _, key := range jwk.Keys {
var publicKey crypto.PublicKey r.publicKeys[key.Kid], err = key.DecodePublicKey()
publicKey, err = key.DecodePublicKey()
if err != nil { if err != nil {
return err return err
} }
r.publicKeys[key.Kid] = publicKey
} }
return nil return nil
@ -215,10 +212,18 @@ func LookupConfig(args JWKSArgs, transport *http.Transport, closeRespFn func(io.
if err != nil { if err != nil {
return args, err return args, err
} }
args.URL = u
if err := args.PopulatePublicKey(); err != nil { args = JWKSArgs{
URL: u,
publicKeys: make(map[string]crypto.PublicKey),
transport: transport,
closeRespFn: closeRespFn,
}
if err = args.PopulatePublicKey(); err != nil {
return args, err return args, err
} }
return args, nil return args, nil
} }

Loading…
Cancel
Save