Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper/schema: Prevent crash on removal of computed field in CustomizeDiff #17261

Merged
merged 1 commit into from
Feb 1, 2018

Conversation

radeksimko
Copy link
Member

We already perform the cleanup in here:

// Remove any nil diffs just to keep things clean
for k, v := range result.Attributes {
if v == nil {
delete(result.Attributes, k)
}
}

however CustomizeDiff was called before this cleanup and therefore any Get(), GetOk() etc. may have caused a crash.

Before fix

=== RUN   TestSchemaMap_Diff/80-optional,_computed,_empty_string_should_not_crash_in_CustomizeDiff
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x21 pc=0x169bc8b]

goroutine 258 [running]:
testing.tRunner.func1(0xc420476c30)
	/usr/local/Cellar/go/1.9.3/libexec/src/testing/testing.go:711 +0x2d2
panic(0x18360e0, 0x1e1b3f0)
	/usr/local/Cellar/go/1.9.3/libexec/src/runtime/panic.go:491 +0x283
github.com/hashicorp/terraform/helper/schema.(*DiffFieldReader).readSet(0xc42045daa0, 0xc4200ff1a0, 0x1, 0x1, 0xc420477a40, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/radeksimko/gopath/src/github.com/hashicorp/terraform/helper/schema/field_reader_diff.go:183 +0x1bb
github.com/hashicorp/terraform/helper/schema.(*DiffFieldReader).ReadField(0xc42045daa0, 0xc4200ff1a0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/radeksimko/gopath/src/github.com/hashicorp/terraform/helper/schema/field_reader_diff.go:73 +0x76e
github.com/hashicorp/terraform/helper/schema.(*MultiLevelFieldReader).ReadFieldMerge(0xc420449900, 0xc4200ff1a0, 0x1, 0x1, 0x1911a3e, 0x7, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/radeksimko/gopath/src/github.com/hashicorp/terraform/helper/schema/field_reader_multi.go:45 +0x260
github.com/hashicorp/terraform/helper/schema.(*ResourceDiff).get(0xc420461d80, 0xc4200ff1a0, 0x1, 0x1, 0x1911a3e, 0x7, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/radeksimko/gopath/src/github.com/hashicorp/terraform/helper/schema/resource_diff.go:406 +0xe3
github.com/hashicorp/terraform/helper/schema.(*ResourceDiff).GetOk(0xc420461d80, 0x1916afb, 0xd, 0xc420449900, 0xc4204498e0, 0xc4200ff190)
	/Users/radeksimko/gopath/src/github.com/hashicorp/terraform/helper/schema/resource_diff.go:338 +0xa6
github.com/hashicorp/terraform/helper/schema.TestSchemaMap_Diff.func39(0xc420461d80, 0x0, 0x0, 0xc420449480, 0xc420461d80)
	/Users/radeksimko/gopath/src/github.com/hashicorp/terraform/helper/schema/schema_test.go:3177 +0x44
github.com/hashicorp/terraform/helper/schema.schemaMap.Diff(0xc4202a3890, 0xc420011e50, 0xc42045d5f0, 0x1942df0, 0x0, 0x0, 0xc420020000, 0x1b02dc0, 0x1b02e00)
	/Users/radeksimko/gopath/src/github.com/hashicorp/terraform/helper/schema/schema.go:435 +0xb62
github.com/hashicorp/terraform/helper/schema.TestSchemaMap_Diff.func40(0xc420476c30)
	/Users/radeksimko/gopath/src/github.com/hashicorp/terraform/helper/schema/schema_test.go:3211 +0x130
testing.tRunner(0xc420476c30, 0xc420040650)
	/usr/local/Cellar/go/1.9.3/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
	/usr/local/Cellar/go/1.9.3/libexec/src/testing/testing.go:789 +0x2de
exit status 2

This is currently a blocker for hashicorp/terraform-provider-aws#3194

@ghost
Copy link

ghost commented Apr 5, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants