From 91b171d46805e6c5427fc6f9018347d0e50ce74a Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 24 Jan 2024 11:10:16 -0500 Subject: [PATCH] fix: prevent panic if length range is out of bounds for message --- protocol/storage_location.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/protocol/storage_location.go b/protocol/storage_location.go index c92672d..536dca5 100644 --- a/protocol/storage_location.go +++ b/protocol/storage_location.go @@ -57,6 +57,9 @@ func (s *StorageLocation) HandleMessage(node interfaces.Node, peer net.Peer, ver for i := 0; i < int(partCount); i++ { length := utils.DecodeEndian(msg[cursor : cursor+2]) cursor += 2 + if len(msg) < cursor+int(length) { + return fmt.Errorf("Invalid message") + } part := string(msg[cursor : cursor+int(length)]) parts = append(parts, part) cursor += int(length)