fix: prevent panic if length range is out of bounds for message

This commit is contained in:
Derrick Hammer 2024-01-24 11:10:16 -05:00
parent 7ca0a67ba5
commit 91b171d468
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 3 additions and 0 deletions

View File

@ -57,6 +57,9 @@ func (s *StorageLocation) HandleMessage(node interfaces.Node, peer net.Peer, ver
for i := 0; i < int(partCount); i++ { for i := 0; i < int(partCount); i++ {
length := utils.DecodeEndian(msg[cursor : cursor+2]) length := utils.DecodeEndian(msg[cursor : cursor+2])
cursor += 2 cursor += 2
if len(msg) < cursor+int(length) {
return fmt.Errorf("Invalid message")
}
part := string(msg[cursor : cursor+int(length)]) part := string(msg[cursor : cursor+int(length)])
parts = append(parts, part) parts = append(parts, part)
cursor += int(length) cursor += int(length)