aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-28 08:48:37 +0800
committerzelig <viktor.tron@gmail.com>2015-04-01 19:32:42 +0800
commite1be34bce1ddf662bca58a37a6f38fea63a2a70f (patch)
tree5751601efa7f3f88ffd5f9903aa0fecb38667bd4 /core
parent936ddf2ad1b7306dfe7f5ae9ca122a4968dd98e8 (diff)
downloadgo-tangerine-e1be34bce1ddf662bca58a37a6f38fea63a2a70f.tar
go-tangerine-e1be34bce1ddf662bca58a37a6f38fea63a2a70f.tar.gz
go-tangerine-e1be34bce1ddf662bca58a37a6f38fea63a2a70f.tar.bz2
go-tangerine-e1be34bce1ddf662bca58a37a6f38fea63a2a70f.tar.lz
go-tangerine-e1be34bce1ddf662bca58a37a6f38fea63a2a70f.tar.xz
go-tangerine-e1be34bce1ddf662bca58a37a6f38fea63a2a70f.tar.zst
go-tangerine-e1be34bce1ddf662bca58a37a6f38fea63a2a70f.zip
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
Diffstat (limited to 'core')
-rw-r--r--core/types/block.go20
1 files changed, 20 insertions, 0 deletions
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 {