Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Safely handle records without ResourceRecords #88

Merged
merged 5 commits into from
Feb 28, 2017

Conversation

mikkeloscar
Copy link
Collaborator

@mikkeloscar mikkeloscar commented Feb 24, 2017

Always check the length of ResourceRecords before trying to index.

Fix #87

@snoby this should fix the issue you were seeing. I have built an image mikkeloscar/mate:v0.6.0-1-gfbdce6b which you can try out if you like.

You can also build your own image:

$ IMAGE=your_user/mate make build.push

Where your_user is your docker hub username.

/cc @ideahitme @linki

Always check the length of ResourceRecords before trying to index.

Fix #87
@ideahitme
Copy link
Contributor

ideahitme commented Feb 24, 2017

@mikkeloscar I agree that the slice length should be checked, however I would love us to get a better understanding of why the TXT record has an empty RR slice. IIRC this is not possible, so maybe we can try to get more details from the issue raiser

@ideahitme
Copy link
Contributor

/cc @mikkeloscar @linki let's merge now and see if the issue persists. add some logging

@mikkeloscar
Copy link
Collaborator Author

lgtm

@mikkeloscar
Copy link
Collaborator Author

👍

groupIDMap[aws.StringValue(record.Name)] = aws.StringValue(record.ResourceRecords[0].Value)
} else {
log.Errorf("Unexpected response from AWS API, got TXT record with empty resources: %s. Record is excluded from syncing", aws.StringValue(record.Name))
groupIDMap[aws.StringValue(record.Name)] = ""
Copy link
Owner

Choose a reason for hiding this comment

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

If I comment out this line then no test fails. Since it's important that we "block" the record name in this case I would love to see something fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

@linki yes, to enable that need to split the function into two parts 1. building dnsname->groupId map and building dnsName->recordInfo map. Thanks for good catch 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@linki added some test, it is ugly, but I didn't want to spend too much time on this

consumers/aws.go Outdated
groupIDMap := map[string]string{} //maps dns to group ID

for _, record := range records {
if aws.StringValue(record.Type) == "TXT" {
if len(record.ResourceRecords) > 0 {
groupIDMap[aws.StringValue(record.Name)] = aws.StringValue(record.ResourceRecords[0].Value)
} else {
log.Errorf("Unexpected response from AWS API, got TXT record with empty resources: %s. Record is excluded from syncing", aws.StringValue(record.Name))
log.Errorf("Unexpected response from AWS API, got TXT record with empty resources: %s . Record is excluded from syncing", aws.StringValue(record.Name))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

minor nitpick. The space looks wrong here.

@ideahitme
Copy link
Contributor

/cc @mikkeloscar @linki please merge if everything is fine and we can ask @snoby to give it another try

@linki
Copy link
Owner

linki commented Feb 28, 2017

👍

@ideahitme ideahitme merged commit b130c56 into master Feb 28, 2017
@ideahitme ideahitme deleted the bugfix/safe-resource-records branch February 28, 2017 09:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

runtime error: index out of range
3 participants