Merge pull request #760 from HynoR/master

fix: Fix slice out-of-bounds issues in ParseUDPMessage.
This commit is contained in:
Toby
2023-10-19 19:31:37 -07:00
committed by GitHub

View File

@@ -212,6 +212,10 @@ func ParseUDPMessage(msg []byte) (*UDPMessage, error) {
return nil, errors.ProtocolError{Message: "invalid address length"}
}
bs := buf.Bytes()
if len(bs) <= int(lAddr) {
// We use <= instead of < here as we expect at least one byte of data after the address
return nil, errors.ProtocolError{Message: "invalid message length"}
}
m.Addr = string(bs[:lAddr])
m.Data = bs[lAddr:]
return m, nil