Merge pull request #20891 from hashicorp/b-helper-schema-setSet-panic

helper/schema: Prevent setSet() panic with typed nil
This commit is contained in:
Brian Flad 2019-04-03 08:52:38 -04:00 committed by GitHub
commit d5a8545a15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -341,6 +341,11 @@ func (w *MapFieldWriter) setSet(
// problems when the old data isn't wiped first. // problems when the old data isn't wiped first.
w.clearTree(addr) w.clearTree(addr)
if value.(*Set) == nil {
w.result[k+".#"] = "0"
return nil
}
for code, elem := range value.(*Set).m { for code, elem := range value.(*Set).m {
if err := w.set(append(addrCopy, code), elem); err != nil { if err := w.set(append(addrCopy, code), elem); err != nil {
return err return err

View File

@ -203,6 +203,15 @@ func TestMapFieldWriter(t *testing.T) {
}, },
}, },
"set typed nil": {
[]string{"set"},
func() *Set { return nil }(),
false,
map[string]string{
"set.#": "0",
},
},
"set resource": { "set resource": {
[]string{"setDeep"}, []string{"setDeep"},
[]interface{}{ []interface{}{