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
This commit is contained in:
Klaus Post 2024-11-05 04:37:59 -08:00 committed by GitHub
parent 7cb4b5c636
commit 8d42f37e4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -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]