From cc7550785f9a1306bc151fa399e5801227929af3 Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 13 Jul 2016 10:17:51 +0200 Subject: [PATCH] swarm/network: guard against short data in store requests --- swarm/network/depo.go | 4 ++-- swarm/network/protocol.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/swarm/network/depo.go b/swarm/network/depo.go index 3b91920f03..97061fe29e 100644 --- a/swarm/network/depo.go +++ b/swarm/network/depo.go @@ -112,7 +112,7 @@ func (self *Depo) HandleStoreRequestMsg(req *storeRequestMsgData, p *peer) { } // update chunk with size and data - chunk.SData = req.SData + chunk.SData = req.SData // protocol validates that SData is minimum 9 bytes long (int64 size + at least one byte of data) chunk.Size = int64(binary.LittleEndian.Uint64(req.SData[0:8])) glog.V(logger.Detail).Infof("[BZZ] delivery of %p from %v", chunk, p) chunk.Source = p @@ -136,7 +136,7 @@ func (self *Depo) HandleRetrieveRequestMsg(req *retrieveRequestMsgData, p *peer) // call storage.NetStore#Get which // blocks until local retrieval finished - // launches cloud retrieval in a separate go routine + // launches cloud retrieval chunk, _ := self.netStore.Get(req.Key) req = self.strategyUpdateRequest(chunk.Req, req) // check if we can immediately deliver diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go index 7ba7755e34..7e45fde094 100644 --- a/swarm/network/protocol.go +++ b/swarm/network/protocol.go @@ -226,6 +226,9 @@ func (self *bzz) handle() error { if err := msg.Decode(&req); err != nil { return self.protoError(ErrDecode, "<- %v: %v", msg, err) } + if len(req.SData) < 9 { + return self.protoError(ErrDecode, "<- %v: Data too short (%v)", msg) + } glog.V(logger.Detail).Infof("[BZZ] incoming store request: %s", req.String()) // swap accounting is done within forwarding self.storage.HandleStoreRequestMsg(&req, &peer{bzz: self})