Unverified Commit 7ea3d725 authored by Matthew Fisher's avatar Matthew Fisher Committed by Matt Farina
Browse files

fix(engine): allow limited recursion in templates


This is a backport for PR 7443.

Signed-off-by: default avatarMatthew Fisher <matt.fisher@microsoft.com>
(cherry picked from commit af3a0214)
No related merge requests found
Showing with 9 additions and 6 deletions
+9 -6
......@@ -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
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment