From 01ea424838a8dc5bfbe57aec4fee61a143a02e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 27 May 2022 07:24:02 +0800 Subject: [PATCH] Cast 4in6 from reading socksaddr --- common/buf/buffer.go | 2 +- common/metadata/serializer.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/buf/buffer.go b/common/buf/buffer.go index 9df069a..0f79c8f 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -94,7 +94,7 @@ func (b *Buffer) Write(data []byte) (n int, err error) { return 0, io.ErrShortBuffer } if b.end+len(data) > b.Cap() { - panic("buffer overflow") + panic("buffer overflow: cap " + strconv.Itoa(len(b.data)) + ",end " + strconv.Itoa(b.end) + ", need " + strconv.Itoa(len(data))) } n = copy(b.data[b.end:], data) b.end += n diff --git a/common/metadata/serializer.go b/common/metadata/serializer.go index 0f17e29..4c3dc37 100644 --- a/common/metadata/serializer.go +++ b/common/metadata/serializer.go @@ -122,7 +122,11 @@ func (s *Serializer) ReadAddress(reader io.Reader) (Socksaddr, error) { if err != nil { return Socksaddr{}, E.Cause(err, "read ipv6 address") } - return Socksaddr{Addr: netip.AddrFrom16(addr)}, nil + netAddr := netip.AddrFrom16(addr) + if netAddr.Is4In6() { + netAddr = netip.AddrFrom4(netAddr.As4()) + } + return Socksaddr{Addr: netAddr}, nil default: return Socksaddr{}, E.New("unknown address family: ", af) }