mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-05 07:50:24 +08:00
fix(recv): panic on short data len
This commit is contained in:
@@ -130,6 +130,12 @@ func (m *Me) listen() (conn p2p.Conn, err error) {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if n <= 0 {
|
||||||
|
if config.ShowDebugLog {
|
||||||
|
logrus.Debugln("[listen] unexpected read n =", n)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
lq := lstnq{
|
lq := lstnq{
|
||||||
index: -1,
|
index: -1,
|
||||||
addr: addr,
|
addr: addr,
|
||||||
|
|||||||
@@ -32,8 +32,19 @@ func (m *Me) wait(data []byte) *head.Packet {
|
|||||||
}
|
}
|
||||||
if m.base14 {
|
if m.base14 {
|
||||||
data = base14.Decode(data)
|
data = base14.Decode(data)
|
||||||
|
if len(data) < bound {
|
||||||
|
bound = len(data)
|
||||||
|
endl = "."
|
||||||
|
}
|
||||||
|
if config.ShowDebugLog {
|
||||||
|
logrus.Debugln("[recv] data b14ed", hex.EncodeToString(data[:bound]), endl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
seq, data := m.xordec(data)
|
seq, data := m.xordec(data)
|
||||||
|
if len(data) < bound {
|
||||||
|
bound = len(data)
|
||||||
|
endl = "."
|
||||||
|
}
|
||||||
if config.ShowDebugLog {
|
if config.ShowDebugLog {
|
||||||
logrus.Debugln("[recv] data xored", hex.EncodeToString(data[:bound]), endl)
|
logrus.Debugln("[recv] data xored", hex.EncodeToString(data[:bound]), endl)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ func (p *packet) ReadFrom(r io.Reader) (n int64, err error) {
|
|||||||
}
|
}
|
||||||
if binary.LittleEndian.Uint32(buf[:]) != magic {
|
if binary.LittleEndian.Uint32(buf[:]) != magic {
|
||||||
err = ErrInvalidMagic
|
err = ErrInvalidMagic
|
||||||
|
if config.ShowDebugLog {
|
||||||
|
logrus.Debugf("[tcp] expect magic %08x but got %08x", magic, binary.LittleEndian.Uint32(buf[:]))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cnt, err = io.ReadFull(r, buf[:3])
|
cnt, err = io.ReadFull(r, buf[:3])
|
||||||
|
|||||||
@@ -258,7 +258,10 @@ func (conn *Conn) receive(tcpconn *net.TCPConn, hasvalidated bool) {
|
|||||||
if config.ShowDebugLog {
|
if config.ShowDebugLog {
|
||||||
logrus.Debugln("[tcp] recv from", ep, "err:", err)
|
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()
|
_ = tcpconn.CloseRead()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user