-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(mapper): prevent index out of bounds in ToEndpointName with multi-dot suffix #6433
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,6 +107,27 @@ func TestAffixNameMapper_ToEndpointName(t *testing.T) { | |
| wantEndpointName: "foo.example.com", | ||
| wantRecordType: endpoint.RecordTypeCNAME, | ||
| }, | ||
| { | ||
| name: "suffix with multiple dots and trailing labels", | ||
| mapper: NewAffixNameMapper("", ".foo.bar", ""), | ||
| input: "a-example.foo.bar.com", | ||
| wantEndpointName: "example.com", | ||
| wantRecordType: endpoint.RecordTypeA, | ||
| }, | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no direct test case for the full path with trailing labels - e.g., a-example.foo.bar.com with suffix .foo.bar should return ("example.com", "A"). The TestToEndpointNameNewTXT round-trip test for "suffix with multiple dots" covers a 3-dot suffix case indirectly, but adding an explicit assertion for trailing labels with a 2-dot suffix would close the gap and document the expected behavior.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, that was an oversight on my part. Added an explicit test for a-example.foo.bar.com with suffix .foo.bar expecting ("example.com", "A"). |
||
| name: "suffix with multiple dots and no trailing labels", | ||
| mapper: NewAffixNameMapper("", ".foo.bar", ""), | ||
| input: "a-example.foo.bar", | ||
| wantEndpointName: "example", | ||
| wantRecordType: endpoint.RecordTypeA, | ||
| }, | ||
| { | ||
| name: "suffix with multiple dots and too few labels does not panic", | ||
| mapper: NewAffixNameMapper("", ".foo.bar", ""), | ||
| input: "a-example.foo", | ||
| wantEndpointName: "", | ||
| wantRecordType: "", | ||
| }, | ||
| { | ||
| name: "no affix with A record", | ||
| mapper: NewAffixNameMapper("", "", ""), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong here. The early-exit guard calling dropAffixExtractType(lowerDNSName) when there are too few labels is fine, but it's misleading - the name can't possibly match the suffix at that point, so it always returns ("", ""). Being explicit is cleaner. Also, domainWithSuffix can be inlined:
^ Same algorithm, no slightly misleading fallthrough call, no intermediate variable. The parts name is also more conventional than DNSName in Go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have addressed this as well in the latest commit