From 36aa63b3384ae976756e28856db5bb2e50c070ba Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Wed, 31 May 2017 09:35:53 -0700 Subject: [PATCH] helper/schema: Guard against out of range on childAddrOf This could panic if we sent a parent that was actually longer than the child (should almost never come up, but the guard will make it safe anyway). Also fixed a slice style lint warning in UpdatedKeys. --- helper/schema/resource_diff.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/helper/schema/resource_diff.go b/helper/schema/resource_diff.go index 96e1d1cbd3..e43156381d 100644 --- a/helper/schema/resource_diff.go +++ b/helper/schema/resource_diff.go @@ -197,7 +197,7 @@ func newResourceDiff(schema map[string]*Schema, config *terraform.ResourceConfig // UpdatedKeys returns the keys that were updated by SetNew, SetNewComputed, or // SetDiff. These are the only keys that a diff should be re-calculated for. func (d *ResourceDiff) UpdatedKeys() []string { - s := make([]string, 0) + var s []string for k := range d.updatedKeys { s = append(s, k) } @@ -435,5 +435,8 @@ func (d *ResourceDiff) finalizeResult(addr []string, result FieldReadResult) get func childAddrOf(child, parent string) bool { cs := strings.Split(child, ".") ps := strings.Split(parent, ".") + if len(ps) > len(cs) { + return false + } return reflect.DeepEqual(ps, cs[:len(ps)]) }