plugin/pkg/dnsutil: guard Join against an empty label slice (#8225)

This commit is contained in:
Omkhar Arasaratnam
2026-07-04 20:02:53 -04:00
committed by GitHub
parent 7abc21bc49
commit 9226f8a3aa
2 changed files with 12 additions and 0 deletions

View File

@@ -10,6 +10,9 @@ import (
// the root label it is ignored. Not other syntax checks are performed.
func Join(labels ...string) string {
ll := len(labels)
if ll == 0 {
return "."
}
if labels[ll-1] == "." {
return strings.Join(labels[:ll-1], ".") + "."
}

View File

@@ -19,3 +19,12 @@ func TestJoin(t *testing.T) {
}
}
}
func TestJoinEmpty(t *testing.T) {
// Join called with no labels must not index labels[ll-1] out of range; it
// returns the root name. Callers on the MX/SRV path can reach Join with an
// empty label slice.
if x := Join(); x != "." {
t.Errorf("expected %q, got %q", ".", x)
}
}