From 8d42f37e4b4e1d779e076ea3eebc14cb31a14cfa Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Tue, 5 Nov 2024 04:37:59 -0800 Subject: [PATCH] Fix msgUnPath crash (#20614) These are needed checks for the functions to be un-crashable with any input given to `msgUnPath` (tested with fuzzing). Both conditions would result in a crash, which prevents that. Some additional upstream checks are needed. Fixes #20610 --- internal/config/dns/dns_path.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/config/dns/dns_path.go b/internal/config/dns/dns_path.go index 94b238045..c648aed2d 100644 --- a/internal/config/dns/dns_path.go +++ b/internal/config/dns/dns_path.go @@ -37,6 +37,9 @@ func msgPath(s, prefix string) string { // dnsJoin joins labels to form a fully qualified domain name. If the last label is // the root label it is ignored. Not other syntax checks are performed. func dnsJoin(labels ...string) string { + if len(labels) == 0 { + return "" + } ll := len(labels) if labels[ll-1] == "." { return strings.Join(labels[:ll-1], ".") + "." @@ -50,6 +53,9 @@ func msgUnPath(s string) string { if l[len(l)-1] == "" { l = l[:len(l)-1] } + if len(l) < 2 { + return s + } // start with 1, to strip /skydns for i, j := 1, len(l)-1; i < j; i, j = i+1, j-1 { l[i], l[j] = l[j], l[i]