From c99ea652e37a78dd34941023c1d4cc32c0654ecd Mon Sep 17 00:00:00 2001 From: Andrey Meshkov Date: Fri, 23 Apr 2021 10:09:34 +0300 Subject: [PATCH] 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 --- svcb.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/svcb.go b/svcb.go index ec0a76f4..64800daa 100644 --- a/svcb.go +++ b/svcb.go @@ -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, } }