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

Added index check for parsing record ID to avoid panic #21501

Merged
merged 1 commit into from
Nov 9, 2021
Merged

Added index check for parsing record ID to avoid panic #21501

merged 1 commit into from
Nov 9, 2021

Conversation

ganchiku
Copy link
Contributor

@ganchiku ganchiku commented Oct 26, 2021

Community Note

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

Why

When specifying wrong format for the recordID, the panic occurs. The index check is not enough. This fix avoids panic, and instead return the empty string value, so that caller can handle error properly.

I encountered the panic as follows, so I added the if condition to avoid the panic to fix this.

Stack trace from the terraform-provider-aws_v3.63.0_x5 plugin:

✗ terraform import aws_route53_record.example ZONEID_example.com

panic: runtime error: slice bounds out of range [:-1]

goroutine 90 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.parseRecordId(0xc000336ab0, 0x24, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/resource_aws_route53_record.go:976 +0x4d2
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsRoute53RecordRead(0xc00014fd80, 0x74553e0, 0xc001766000, 0xca078f0, 0xc0006d4000)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/resource_aws_route53_record.go:515 +0x1b57
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc000c4db20, 0x8f161a8, 0xc002303100, 0xc00014fd80, 0x74553e0, 0xc001766000, 0x0, 0x0, 0x0)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/v2@v2.7.1-0.20210913224932-c7c2dbd9e010/helper/schema/resource.go:335 +0x1ee
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000c4db20, 0x8f161a8, 0xc002303100, 0xc0022da850, 0x74553e0, 0xc001766000, 0xc000114880, 0x0, 0x0, 0x0)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/v2@v2.7.1-0.20210913224932-c7c2dbd9e010/helper/schema/resource.go:624 +0x1cb
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc00000c870, 0x8f161a8, 0xc002303100, 0xc002303140, 0xc002303100, 0x100b665, 0x7ddaba0)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/v2@v2.7.1-0.20210913224932-c7c2dbd9e010/helper/schema/grpc_provider.go:575 +0x43b
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ReadResource(0xc0020e5600, 0x8f16250, 0xc002303100, 0xc001262c00, 0xc0020e5600, 0xc0016098c0, 0xc0006ecba0)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/server/server.go:298 +0x105
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler(0x80d3a00, 0xc0020e5600, 0x8f16250, 0xc0016098c0, 0xc001262b40, 0x0, 0x8f16250, 0xc0016098c0, 0xc0001b8b00, 0x14e)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.3.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:344 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002b5a40, 0x8f3a098, 0xc0006d6300, 0xc0022faa00, 0xc000d80810, 0xc9c6190, 0x0, 0x0, 0x0)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:1194 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc0002b5a40, 0x8f3a098, 0xc0006d6300, 0xc0022faa00, 0x0)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:1517 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000864260, 0xc0002b5a40, 0x8f3a098, 0xc0006d6300, 0xc0022faa00)
    /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:859 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
    /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:857 +0x1fd

Error: The terraform-provider-aws_v3.63.0_x5 plugin crashed!

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccRoute53Record_basic' PKG_NAME=internal/service/route53
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/route53/... -v -count 1 -parallel 20 -run=TestAccRoute53Record_basic -timeout 180m
=== RUN   TestAccRoute53Record_basic
=== PAUSE TestAccRoute53Record_basic
=== CONT  TestAccRoute53Record_basic
--- PASS: TestAccRoute53Record_basic (169.84s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/route53	171.549s

@github-actions github-actions bot added service/route53 Issues and PRs that pertain to the route53 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/XS Managed by automation to categorize the size of a PR. needs-triage Waiting for first response or review from a maintainer. labels Oct 26, 2021
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome @ganchiku 👋

It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.

Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.

Thanks again, and welcome to the community! 😃

@ganchiku ganchiku marked this pull request as ready for review October 26, 2021 16:42
@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Oct 26, 2021
@YakDriver YakDriver self-assigned this Nov 9, 2021
Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

Output from tests:

% TF_ACC=1 go test ./internal/service/route53 -v -count 1 -parallel 20 -run='TestParseRecordId' -timeout=180m
--- PASS: TestParseRecordId (0.00s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/route53	1.088s
% TF_ACC=1 go test ./internal/service/route53 -v -count 1 -parallel 20 -run='TestAccRoute53Record_basic' -timeout=180m
--- PASS: TestAccRoute53Record_basic (154.77s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/route53	155.869s

@YakDriver YakDriver added this to the v3.65.0 milestone Nov 9, 2021
@YakDriver YakDriver merged commit e4288f2 into hashicorp:main Nov 9, 2021
@github-actions
Copy link

This functionality has been released in v3.65.0 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!

@github-actions
Copy link

github-actions bot commented Jun 9, 2022

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 Jun 9, 2022
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. service/route53 Issues and PRs that pertain to the route53 service. size/XS Managed by automation to categorize the size of a PR. 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.

3 participants