core: fix crash when computed nested map given in module block

This crash resulted because the type switch checked for either of two
types but the type assertion within it assumed only one of them.

A straightforward (if inelegant) fix is to simply duplicate the relevant
case block and change the type assertion, thus allowing the types to match
up in all cases.

This fixes #13297.
This commit is contained in:
Martin Atkins 2017-04-04 12:01:13 -07:00
parent 6980e14191
commit c1c5c9a2f6

View File

@ -174,9 +174,15 @@ func (n *EvalVariableBlock) setUnknownVariableValueForPath(path string) error {
// Otherwise find the correct point in the tree and then set to unknown
var current interface{} = n.VariableValues[pathComponents[0]]
for i := 1; i < len(pathComponents); i++ {
switch current.(type) {
case []interface{}, []map[string]interface{}:
tCurrent := current.([]interface{})
switch tCurrent := current.(type) {
case []interface{}:
index, err := strconv.Atoi(pathComponents[i])
if err != nil {
return fmt.Errorf("Cannot convert %s to slice index in path %s",
pathComponents[i], path)
}
current = tCurrent[index]
case []map[string]interface{}:
index, err := strconv.Atoi(pathComponents[i])
if err != nil {
return fmt.Errorf("Cannot convert %s to slice index in path %s",
@ -184,7 +190,6 @@ func (n *EvalVariableBlock) setUnknownVariableValueForPath(path string) error {
}
current = tCurrent[index]
case map[string]interface{}:
tCurrent := current.(map[string]interface{})
if val, hasVal := tCurrent[pathComponents[i]]; hasVal {
current = val
continue