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.
This commit is contained in:
Chris Marchesi 2017-05-31 09:35:53 -07:00 committed by Martin Atkins
parent 931b0e1441
commit 36aa63b338
1 changed files with 4 additions and 1 deletions

View File

@ -197,7 +197,7 @@ func newResourceDiff(schema map[string]*Schema, config *terraform.ResourceConfig
// UpdatedKeys returns the keys that were updated by SetNew, SetNewComputed, or // 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. // SetDiff. These are the only keys that a diff should be re-calculated for.
func (d *ResourceDiff) UpdatedKeys() []string { func (d *ResourceDiff) UpdatedKeys() []string {
s := make([]string, 0) var s []string
for k := range d.updatedKeys { for k := range d.updatedKeys {
s = append(s, k) s = append(s, k)
} }
@ -435,5 +435,8 @@ func (d *ResourceDiff) finalizeResult(addr []string, result FieldReadResult) get
func childAddrOf(child, parent string) bool { func childAddrOf(child, parent string) bool {
cs := strings.Split(child, ".") cs := strings.Split(child, ".")
ps := strings.Split(parent, ".") ps := strings.Split(parent, ".")
if len(ps) > len(cs) {
return false
}
return reflect.DeepEqual(ps, cs[:len(ps)]) return reflect.DeepEqual(ps, cs[:len(ps)])
} }