cmd/rlpdump, cmd/utils, eth, p2p, whisper: use rlp input limit

pull/711/head
Felix Lange 10 years ago
parent c35f4fd0bd
commit 56a48101dc
  1. 2
      cmd/rlpdump/main.go
  2. 2
      cmd/utils/cmd.go
  3. 6
      eth/protocol.go
  4. 3
      p2p/message.go
  5. 2
      whisper/peer.go

@ -78,7 +78,7 @@ func main() {
os.Exit(2)
}
s := rlp.NewStream(r)
s := rlp.NewStream(r, 0)
for {
if err := dump(s, 0); err != nil {
if err != io.EOF {

@ -154,7 +154,7 @@ func ImportChain(chainmgr *core.ChainManager, fn string) error {
defer fh.Close()
chainmgr.Reset()
stream := rlp.NewStream(fh)
stream := rlp.NewStream(fh, 0)
var i, n int
batchSize := 2500

@ -210,7 +210,7 @@ func (self *ethProtocol) handle() error {
return p2p.Send(self.rw, BlockHashesMsg, hashes)
case BlockHashesMsg:
msgStream := rlp.NewStream(msg.Payload)
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
if _, err := msgStream.List(); err != nil {
return err
}
@ -231,7 +231,7 @@ func (self *ethProtocol) handle() error {
self.blockPool.AddBlockHashes(iter, self.id)
case GetBlocksMsg:
msgStream := rlp.NewStream(msg.Payload)
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
if _, err := msgStream.List(); err != nil {
return err
}
@ -259,7 +259,7 @@ func (self *ethProtocol) handle() error {
return p2p.Send(self.rw, BlocksMsg, blocks)
case BlocksMsg:
msgStream := rlp.NewStream(msg.Payload)
msgStream := rlp.NewStream(msg.Payload, uint64(msg.Size))
if _, err := msgStream.List(); err != nil {
return err
}

@ -32,7 +32,8 @@ type Msg struct {
//
// For the decoding rules, please see package rlp.
func (msg Msg) Decode(val interface{}) error {
if err := rlp.Decode(msg.Payload, val); err != nil {
s := rlp.NewStream(msg.Payload, uint64(msg.Size))
if err := s.Decode(val); err != nil {
return newPeerError(errInvalidMsg, "(code %x) (size %d) %v", msg.Code, msg.Size, err)
}
return nil

@ -66,7 +66,7 @@ func (self *peer) handshake() error {
if packet.Code != statusCode {
return fmt.Errorf("peer sent %x before status packet", packet.Code)
}
s := rlp.NewStream(packet.Payload)
s := rlp.NewStream(packet.Payload, uint64(packet.Size))
if _, err := s.List(); err != nil {
return fmt.Errorf("bad status message: %v", err)
}

Loading…
Cancel
Save