From e1be34bce1ddf662bca58a37a6f38fea63a2a70f Mon Sep 17 00:00:00 2001 From: zelig Date: Sat, 28 Mar 2015 00:48:37 +0000 Subject: eth: SEC-29 eth wire protocol decoding invalid message data crashes client - add validate method to types.Block - validate after Decode -> error - add tests for NewBlockMsg --- core/types/block.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'core') diff --git a/core/types/block.go b/core/types/block.go index 5cdde4462..c04beae5a 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -148,6 +148,26 @@ func NewBlockWithHeader(header *Header) *Block { return &Block{header: header} } +func (self *Block) Validate() error { + if self.header == nil { + return fmt.Errorf("header is nil") + } + // check *big.Int fields + if self.header.Difficulty == nil { + return fmt.Errorf("Difficulty undefined") + } + if self.header.GasLimit == nil { + return fmt.Errorf("GasLimit undefined") + } + if self.header.GasUsed == nil { + return fmt.Errorf("GasUsed undefined") + } + if self.header.Number == nil { + return fmt.Errorf("Number undefined") + } + return nil +} + func (self *Block) DecodeRLP(s *rlp.Stream) error { var eb extblock if err := s.Decode(&eb); err != nil { -- cgit