From 901ed9157954571f5e7f6d0d405904a3d7c699ee Mon Sep 17 00:00:00 2001 From: Page Fault Date: Thu, 28 May 2020 09:32:27 +0000 Subject: [PATCH] fix udp payload reading --- protocol/trojan/packet.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/protocol/trojan/packet.go b/protocol/trojan/packet.go index 7d04d2582..d27b38edf 100644 --- a/protocol/trojan/packet.go +++ b/protocol/trojan/packet.go @@ -26,12 +26,15 @@ func (i *TrojanPacketSession) ReadPacket() (*protocol.Request, []byte, error) { lengthBuf := [2]byte{} _, err := io.ReadFull(i.conn, lengthBuf[:]) if err != nil { - return req, nil, common.NewError("failed to read length") + return req, nil, common.NewError("Failed to read length") } length := binary.BigEndian.Uint16(lengthBuf[:]) packet := make([]byte, length) - n, err := i.conn.Read(packet) - return req, packet[:n], err + _, err = io.ReadFull(i.conn, packet) + if err != nil { + return req, nil, common.NewError("Failed to read payload") + } + return req, packet[:], err } func (i *TrojanPacketSession) WritePacket(req *protocol.Request, packet []byte) (int, error) {