mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-11 20:20:27 +08:00
fix(recv): panic on short data len
This commit is contained in:
@@ -63,6 +63,9 @@ func (p *packet) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
}
|
||||
if binary.LittleEndian.Uint32(buf[:]) != magic {
|
||||
err = ErrInvalidMagic
|
||||
if config.ShowDebugLog {
|
||||
logrus.Debugf("[tcp] expect magic %08x but got %08x", magic, binary.LittleEndian.Uint32(buf[:]))
|
||||
}
|
||||
return
|
||||
}
|
||||
cnt, err = io.ReadFull(r, buf[:3])
|
||||
|
||||
@@ -258,7 +258,10 @@ func (conn *Conn) receive(tcpconn *net.TCPConn, hasvalidated bool) {
|
||||
if config.ShowDebugLog {
|
||||
logrus.Debugln("[tcp] recv from", ep, "err:", err)
|
||||
}
|
||||
if errors.Is(err, net.ErrClosed) || errors.Is(err, io.ErrClosedPipe) || errors.Is(err, io.EOF) {
|
||||
if errors.Is(err, net.ErrClosed) ||
|
||||
errors.Is(err, io.ErrClosedPipe) ||
|
||||
errors.Is(err, io.EOF) ||
|
||||
errors.Is(err, ErrInvalidMagic) {
|
||||
_ = tcpconn.CloseRead()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user