diff options
author | Martin Holst Swende <martin@swende.se> | 2019-07-08 17:42:22 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2019-07-08 17:42:22 +0800 |
commit | cdfe9a3a2a257dcd2506e9a0eaf3bf3b0986c43a (patch) | |
tree | a6889c88919d76f825514c2cecc789fc6f62a39d /les/protocol.go | |
parent | 5bc9ccfa0af6e2892c1f40689dfb90a056ba81d6 (diff) | |
download | go-tangerine-cdfe9a3a2a257dcd2506e9a0eaf3bf3b0986c43a.tar go-tangerine-cdfe9a3a2a257dcd2506e9a0eaf3bf3b0986c43a.tar.gz go-tangerine-cdfe9a3a2a257dcd2506e9a0eaf3bf3b0986c43a.tar.bz2 go-tangerine-cdfe9a3a2a257dcd2506e9a0eaf3bf3b0986c43a.tar.lz go-tangerine-cdfe9a3a2a257dcd2506e9a0eaf3bf3b0986c43a.tar.xz go-tangerine-cdfe9a3a2a257dcd2506e9a0eaf3bf3b0986c43a.tar.zst go-tangerine-cdfe9a3a2a257dcd2506e9a0eaf3bf3b0986c43a.zip |
eth, les: add sanity checks for unbounded block fields (#19573)
This PR adds some hardening in the lower levels of the protocol stack, to bail early on invalid data. Primarily, attacks that this PR protects against are on the "annoyance"-level, which would otherwise write a couple of megabytes of data into the log output, which is a bit resource intensive.
Diffstat (limited to 'les/protocol.go')
-rw-r--r-- | les/protocol.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/les/protocol.go b/les/protocol.go index ebf581473..5fdf32b74 100644 --- a/les/protocol.go +++ b/les/protocol.go @@ -149,6 +149,14 @@ type announceData struct { Update keyValueList } +// sanityCheck verifies that the values are reasonable, as a DoS protection +func (a *announceData) sanityCheck() error { + if tdlen := a.Td.BitLen(); tdlen > 100 { + return fmt.Errorf("too large block TD: bitlen %d", tdlen) + } + return nil +} + // sign adds a signature to the block announcement by the given privKey func (a *announceData) sign(privKey *ecdsa.PrivateKey) { rlp, _ := rlp.EncodeToBytes(announceBlock{a.Hash, a.Number, a.Td}) |