Fix nil pointer

This commit is contained in:
Jeff Mitchell 2018-06-09 16:57:57 -04:00
parent 8916f6b625
commit d3cbde6ae2
3 changed files with 18 additions and 5 deletions

View File

@ -22,13 +22,18 @@ func wrapCORSHandler(h http.Handler, core *vault.Core) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
corsConf := core.CORSConfig()
origin := req.Header.Get("Origin")
requestMethod := req.Header.Get("Access-Control-Request-Method")
// If CORS is not enabled or if no Origin header is present (i.e. the request
// is from the Vault CLI. A browser will always send an Origin header), then
// just return a 204.
if !corsConf.IsEnabled() || origin == "" {
if !corsConf.IsEnabled() {
h.ServeHTTP(w, req)
return
}
origin := req.Header.Get("Origin")
requestMethod := req.Header.Get("Access-Control-Request-Method")
if origin == "" {
h.ServeHTTP(w, req)
return
}

View File

@ -517,7 +517,10 @@ func NewCore(conf *CoreConfig) (*Core, error) {
}
// Load CORS config and provide a value for the core field.
c.corsConfig = &CORSConfig{core: c}
c.corsConfig = &CORSConfig{
core: c,
Enabled: new(uint32),
}
phys := conf.Physical
_, txnOK := conf.Physical.(physical.Transactional)

View File

@ -79,6 +79,11 @@ func (c *Core) loadCORSConfig(ctx context.Context) error {
if err != nil {
return err
}
if newConfig.Enabled == nil {
newConfig.Enabled = new(uint32)
}
newConfig.core = c
c.corsConfig = newConfig