plugin/etcd: Stop target stripping at the end of a name (#8584)

Stops stripping when the next-label operation reaches the end sentinel in DNS

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2026-09-29 20:11:44 -07:00
committed by GitHub
parent 23ba070a81
commit 6ad382b53d
2 changed files with 24 additions and 1 deletions

View File

@@ -165,6 +165,9 @@ func targetStrip(name string, targetStrip int) string {
offset, end := 0, false
for range targetStrip {
offset, end = dns.NextLabel(name, offset)
if end {
break
}
}
if end {
// We overshot the name, use the original one.

View File

@@ -1,6 +1,9 @@
package msg
import "testing"
import (
"testing"
"time"
)
func TestSplit255(t *testing.T) {
xs := split255("abc")
@@ -29,6 +32,23 @@ func TestSplit255(t *testing.T) {
}
}
func TestTargetStripLargeValueReturns(t *testing.T) {
const name = "b.z1.test."
done := make(chan string, 1)
go func() {
done <- targetStrip(name, int(^uint(0)>>1))
}()
select {
case got := <-done:
if got != name {
t.Fatalf("targetStrip returned %q, want %q", got, name)
}
case <-time.After(time.Second):
t.Fatal("targetStrip did not return after reaching the end of the name")
}
}
func TestGroup(t *testing.T) {
// Key are in the wrong order, but for this test it does not matter.
sx := Group(