Skip to content

Commit

Permalink
prevent sdk panics in 2 specific cases
Browse files Browse the repository at this point in the history
Fix 2 specific panics in the sdk when reading nil or computed maps from
various configurations. The legacy sdk code is too dependent on undefined
behavior to attempt to find and fix the root cause at this point.

Since the code is essentially frozen for future development, these
changes are specifically targeted to only prevent panics from within
providers.  Because any code effected by these changes would have
panicked, there cannot be anything depending on the behavior, and these
should be safe to fix.
  • Loading branch information
jbardin committed Jun 25, 2019
1 parent fe11724 commit cd3ac50
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions helper/schema/field_reader_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func (r *ConfigFieldReader) readMap(k string, schema *Schema) (FieldReadResult,
v, _ := r.Config.Get(key)
result[ik] = v
}
case nil:
// the map may have been empty on the configuration, so we leave the
// empty result
default:
panic(fmt.Sprintf("unknown type: %#v", mraw))
}
Expand Down
4 changes: 3 additions & 1 deletion helper/schema/field_reader_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ func (r *DiffFieldReader) readMap(
return FieldReadResult{}, err
}
if source.Exists {
result = source.Value.(map[string]interface{})
// readMap may return a nil value, or an unknown value placeholder in
// some cases, causing the type assertion to panic if we don't assign the ok value
result, _ = source.Value.(map[string]interface{})
resultSet = true
}

Expand Down

0 comments on commit cd3ac50

Please sign in to comment.