fix: Fix slice out-of-bounds issues in ParseUDPMessage.

This commit is contained in:
tako 2023-10-20 09:54:41 +08:00
parent e57eeb986b
commit d513ae115b

View file

@ -212,6 +212,9 @@ func ParseUDPMessage(msg []byte) (*UDPMessage, error) {
return nil, errors.ProtocolError{Message: "invalid address length"}
}
bs := buf.Bytes()
if len(bs) < int(lAddr) {
return nil, errors.ProtocolError{Message: "message length mismatch"}
}
m.Addr = string(bs[:lAddr])
m.Data = bs[lAddr:]
return m, nil