swarm/network: guard against short data in store requests

This commit is contained in:
zelig 2016-07-13 10:17:51 +02:00
parent 38120c7d52
commit cc7550785f
2 changed files with 5 additions and 2 deletions

View file

@ -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

View file

@ -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})