From 6000855c82fc1bdc5c256480b4161511f91ed703 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 26 Jun 2019 10:45:34 -0600 Subject: [PATCH] Fix panics by disallowing explicitly-defined null modules in config --- context.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/context.go b/context.go index 2af38ff60..9661aca4d 100644 --- a/context.go +++ b/context.go @@ -100,6 +100,15 @@ func (ctx Context) LoadModule(name string, rawMsg json.RawMessage) (interface{}, } } + if val == nil { + // returned module values are almost always type-asserted + // before being used, so a nil value would panic; and there + // is no good reason to explicitly declare null modules in + // a config; it might be because the user is trying to + // achieve a result they aren't expecting, which is a smell + return nil, fmt.Errorf("module value cannot be null") + } + if prov, ok := val.(Provisioner); ok { err := prov.Provision(ctx) if err != nil {