Skip to content

Commit

Permalink
Fix copy() in SVCBIPv4Hint and SVCBIPv6Hint (#1256)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ameshkov authored Apr 23, 2021
1 parent 8891315 commit c99ea65
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions svcb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
}
}

Expand Down

0 comments on commit c99ea65

Please sign in to comment.