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
commit f854c38870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -212,6 +212,10 @@ func ParseUDPMessage(msg []byte) (*UDPMessage, error) {
return nil, errors.ProtocolError{Message: "invalid address length"} return nil, errors.ProtocolError{Message: "invalid address length"}
} }
bs := buf.Bytes() 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.Addr = string(bs[:lAddr])
m.Data = bs[lAddr:] m.Data = bs[lAddr:]
return m, nil return m, nil