Fix copy() in SVCBIPv4Hint and SVCBIPv6Hint (#1256)

* Fix copy() in SVCBIPv4Hint and SVCBIPv6Hint

The problem with the current implementation is that it is not a real deep copy,
it points to the same base arrays behind the slices. This was causing some
issues in real-life application.

* Address review comments
This commit is contained in:
Andrey Meshkov 2021-04-23 10:09:34 +03:00 committed by GitHub
parent 88913150f0
commit c99ea652e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

14
svcb.go
View File

@ -511,8 +511,13 @@ func (s *SVCBIPv4Hint) parse(b string) error {
}
func (s *SVCBIPv4Hint) copy() SVCBKeyValue {
hint := make([]net.IP, len(s.Hint))
for i, ip := range s.Hint {
hint[i] = copyIP(ip)
}
return &SVCBIPv4Hint{
append([]net.IP(nil), s.Hint...),
Hint: hint,
}
}
@ -629,8 +634,13 @@ func (s *SVCBIPv6Hint) parse(b string) error {
}
func (s *SVCBIPv6Hint) copy() SVCBKeyValue {
hint := make([]net.IP, len(s.Hint))
for i, ip := range s.Hint {
hint[i] = copyIP(ip)
}
return &SVCBIPv6Hint{
append([]net.IP(nil), s.Hint...),
Hint: hint,
}
}