diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 6063fdff0..de9820278 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -32,6 +32,8 @@ import ( "k8s.io/helm/pkg/proto/hapi/chart" ) +const recursionMaxNums = 1000 + // Engine is an implementation of 'cmd/tiller/environment'.Engine that uses Go templates. type Engine struct { // FuncMap contains the template functions that will be passed to each @@ -145,21 +147,22 @@ func (e *Engine) alterFuncMap(t *template.Template, referenceTpls map[string]ren funcMap[k] = v } - includedNames := make([]string, 0) + includedNames := make(map[string]int) // Add the 'include' function here so we can close over t. funcMap["include"] = func(name string, data interface{}) (string, error) { buf := bytes.NewBuffer(nil) - for _, n := range includedNames { - if n == name { - return "", errors.Wrapf(fmt.Errorf("unable to excute template"), "rendering template has a nested reference name: %s", name) + if v, ok := includedNames[name]; ok { + if v > recursionMaxNums { + return "", errors.Wrapf(fmt.Errorf("unable to execute template"), "rendering template has a nested reference name: %s", name) } + includedNames[name]++ + } else { + includedNames[name] = 1 } - includedNames = append(includedNames, name) if err := t.ExecuteTemplate(buf, name, data); err != nil { return "", err } - includedNames = includedNames[:len(includedNames)-1] return buf.String(), nil }