From c5da2f65433f02bc7bf23a838eba7fce404f8395 Mon Sep 17 00:00:00 2001 From: Ghanan Gowripalan Date: Tue, 30 May 2023 12:47:17 -0700 Subject: [PATCH] Limit stringified bytes to address length ...to match the behaviour of Address.String before the change to make Address an opaque type. PiperOrigin-RevId: 536481989 --- pkg/tcpip/tcpip.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go index 513f6ab1f..f0fbe83ac 100644 --- a/pkg/tcpip/tcpip.go +++ b/pkg/tcpip/tcpip.go @@ -2508,7 +2508,7 @@ func clone(dst reflect.Value, src reflect.Value) { // String implements the fmt.Stringer interface. func (a Address) String() string { - switch a.Len() { + switch l := a.Len(); l { case 4: return fmt.Sprintf("%d.%d.%d.%d", int(a.addr[0]), int(a.addr[1]), int(a.addr[2]), int(a.addr[3])) case 16: @@ -2549,7 +2549,7 @@ func (a Address) String() string { } return b.String() default: - return fmt.Sprintf("%x", a.addr[:]) + return fmt.Sprintf("%x", a.addr[:l]) } }