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

internal/flex: handle nil items in FlattenStringList #38886

Merged
merged 1 commit into from
Aug 19, 2024
Merged

Conversation

jar-b
Copy link
Member

@jar-b jar-b commented Aug 15, 2024

Description

Prior to this change, the FlattenStringList function would attempt to dereference nil items when provided in the source slice. Now nil items are skipped and omitted from the resulting []interface{}{} return value.

Before:

% go test -count=1 ./internal/flex/... -run=TestFlattenStringList
--- FAIL: TestFlattenStringList (0.00s)
    --- FAIL: TestFlattenStringList/nil_item (0.00s)
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=0x2 addr=0x0 pc=0x10319c57c]

goroutine 9 [running]:
testing.tRunner.func1.2({0x10369e4c0, 0x103ab3520})
        /Users/jaredbaker/sdk/go1.22.6/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
        /Users/jaredbaker/sdk/go1.22.6/src/testing/testing.go:1634 +0x33c
panic({0x10369e4c0?, 0x103ab3520?})
        /Users/jaredbaker/sdk/go1.22.6/src/runtime/panic.go:770 +0x124
github.com/hashicorp/terraform-provider-aws/internal/flex.FlattenStringList(...)
        /Users/jaredbaker/development/terraform-provider-aws/internal/flex/flex.go:107
github.com/hashicorp/terraform-provider-aws/internal/flex.TestFlattenStringList.func1(0x14000799ba0)
        /Users/jaredbaker/development/terraform-provider-aws/internal/flex/flex_test.go:550 +0x9c
testing.tRunner(0x14000799ba0, 0x14000409ea0)
        /Users/jaredbaker/sdk/go1.22.6/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 6
        /Users/jaredbaker/sdk/go1.22.6/src/testing/testing.go:1742 +0x318
FAIL    github.com/hashicorp/terraform-provider-aws/internal/flex       0.433s

After:

% go test -count=1 ./internal/flex/... -run=TestFlattenStringList
ok      github.com/hashicorp/terraform-provider-aws/internal/flex       0.634s

Relations

Closes #34199

@jar-b jar-b added the bug Addresses a defect in current functionality. label Aug 15, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@jar-b jar-b added the crash Results from or addresses a Terraform crash or kernel panic. label Aug 15, 2024
@github-actions github-actions bot added tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. flex Pertains to FLatteners and EXpanders. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. labels Aug 15, 2024
@jar-b jar-b marked this pull request as ready for review August 15, 2024 16:26
@jar-b jar-b requested a review from a team as a code owner August 15, 2024 16:26
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.

CHANGELOG?

Prior to this change, the `FlattenStringList` function would attempt to dereference `nil` items when provided in the source slice. Now `nil` items are skipped and omitted from the resulting `[]interface{}{}` return value.

Before:

```console
% go test -count=1 ./internal/flex/... -run=TestFlattenStringList
--- FAIL: TestFlattenStringList (0.00s)
    --- FAIL: TestFlattenStringList/nil_item (0.00s)
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=0x2 addr=0x0 pc=0x10319c57c]

goroutine 9 [running]:
testing.tRunner.func1.2({0x10369e4c0, 0x103ab3520})
        /Users/jaredbaker/sdk/go1.22.6/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
        /Users/jaredbaker/sdk/go1.22.6/src/testing/testing.go:1634 +0x33c
panic({0x10369e4c0?, 0x103ab3520?})
        /Users/jaredbaker/sdk/go1.22.6/src/runtime/panic.go:770 +0x124
github.com/hashicorp/terraform-provider-aws/internal/flex.FlattenStringList(...)
        /Users/jaredbaker/development/terraform-provider-aws/internal/flex/flex.go:107
github.com/hashicorp/terraform-provider-aws/internal/flex.TestFlattenStringList.func1(0x14000799ba0)
        /Users/jaredbaker/development/terraform-provider-aws/internal/flex/flex_test.go:550 +0x9c
testing.tRunner(0x14000799ba0, 0x14000409ea0)
        /Users/jaredbaker/sdk/go1.22.6/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 6
        /Users/jaredbaker/sdk/go1.22.6/src/testing/testing.go:1742 +0x318
FAIL    github.com/hashicorp/terraform-provider-aws/internal/flex       0.433s
```

After:

```console
% go test -count=1 ./internal/flex/... -run=TestFlattenStringList
ok      github.com/hashicorp/terraform-provider-aws/internal/flex       0.634s
```
@jar-b jar-b merged commit 3f8f68d into main Aug 19, 2024
30 checks passed
@jar-b jar-b deleted the b-flex-crash branch August 19, 2024 13:49
@github-actions github-actions bot added this to the v5.64.0 milestone Aug 19, 2024
terraform-aws-provider bot pushed a commit that referenced this pull request Aug 19, 2024
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Aug 20, 2024
Copy link

This functionality has been released in v5.63.1 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. flex Pertains to FLatteners and EXpanders. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Nil Pointer Reference on aws_quicksight_data_set when using logical table maps
2 participants