mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 05:09:58 +00:00
TUN-2748: Insecure randomness vulnerability in github.com/miekg/dns
This commit is contained in:
60
vendor/github.com/miekg/dns/labels.go
generated
vendored
60
vendor/github.com/miekg/dns/labels.go
generated
vendored
@@ -126,20 +126,23 @@ func Split(s string) []int {
|
||||
// The bool end is true when the end of the string has been reached.
|
||||
// Also see PrevLabel.
|
||||
func NextLabel(s string, offset int) (i int, end bool) {
|
||||
quote := false
|
||||
if s == "" {
|
||||
return 0, true
|
||||
}
|
||||
for i = offset; i < len(s)-1; i++ {
|
||||
switch s[i] {
|
||||
case '\\':
|
||||
quote = !quote
|
||||
default:
|
||||
quote = false
|
||||
case '.':
|
||||
if quote {
|
||||
quote = !quote
|
||||
continue
|
||||
}
|
||||
return i + 1, false
|
||||
if s[i] != '.' {
|
||||
continue
|
||||
}
|
||||
j := i - 1
|
||||
for j >= 0 && s[j] == '\\' {
|
||||
j--
|
||||
}
|
||||
|
||||
if (j-i)%2 == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
return i + 1, false
|
||||
}
|
||||
return i + 1, true
|
||||
}
|
||||
@@ -149,17 +152,38 @@ func NextLabel(s string, offset int) (i int, end bool) {
|
||||
// The bool start is true when the start of the string has been overshot.
|
||||
// Also see NextLabel.
|
||||
func PrevLabel(s string, n int) (i int, start bool) {
|
||||
if s == "" {
|
||||
return 0, true
|
||||
}
|
||||
if n == 0 {
|
||||
return len(s), false
|
||||
}
|
||||
lab := Split(s)
|
||||
if lab == nil {
|
||||
return 0, true
|
||||
|
||||
l := len(s) - 1
|
||||
if s[l] == '.' {
|
||||
l--
|
||||
}
|
||||
if n > len(lab) {
|
||||
return 0, true
|
||||
|
||||
for ; l >= 0 && n > 0; l-- {
|
||||
if s[l] != '.' {
|
||||
continue
|
||||
}
|
||||
j := l - 1
|
||||
for j >= 0 && s[j] == '\\' {
|
||||
j--
|
||||
}
|
||||
|
||||
if (j-l)%2 == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
n--
|
||||
if n == 0 {
|
||||
return l + 1, false
|
||||
}
|
||||
}
|
||||
return lab[len(lab)-n], false
|
||||
|
||||
return 0, n > 1
|
||||
}
|
||||
|
||||
// equal compares a and b while ignoring case. It returns true when equal otherwise false.
|
||||
|
Reference in New Issue
Block a user