aboutsummaryrefslogtreecommitdiffstats
path: root/eth/handler.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-10-05 21:31:48 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-10-05 21:34:07 +0800
commite482b5694faece927a29289f88d7a87b1ce1fbd1 (patch)
treeeedbb105046f909300744dcd89993ff97a6bb5fa /eth/handler.go
parenta7cc3248fe3ecb3439d0b69f5823f294b2854886 (diff)
downloaddexon-e482b5694faece927a29289f88d7a87b1ce1fbd1.tar.gz
dexon-e482b5694faece927a29289f88d7a87b1ce1fbd1.tar.zst
dexon-e482b5694faece927a29289f88d7a87b1ce1fbd1.zip
eth: monitor malicious header retrieval requests
Diffstat (limited to 'eth/handler.go')
-rw-r--r--eth/handler.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/eth/handler.go b/eth/handler.go
index e6c547c02..d72185dd3 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -17,6 +17,7 @@
package eth
import (
+ "encoding/json"
"errors"
"fmt"
"math"
@@ -371,14 +372,24 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
case query.Origin.Hash != (common.Hash{}) && !query.Reverse:
// Hash based traversal towards the leaf block
- if header := pm.blockchain.GetHeaderByNumber(origin.Number.Uint64() + query.Skip + 1); header != nil {
- if pm.blockchain.GetBlockHashesFromHash(header.Hash(), query.Skip+1)[query.Skip] == query.Origin.Hash {
- query.Origin.Hash = header.Hash()
+ var (
+ current = origin.Number.Uint64()
+ next = current + query.Skip + 1
+ )
+ if next <= current {
+ infos, _ := json.MarshalIndent(p.Peer.Info(), "", " ")
+ glog.V(logger.Warn).Infof("%v: GetBlockHeaders skip overflow attack (current %v, skip %v, next %v)\nMalicious peer infos: %s", p, current, query.Skip, next, infos)
+ unknown = true
+ } else {
+ if header := pm.blockchain.GetHeaderByNumber(next); header != nil {
+ if pm.blockchain.GetBlockHashesFromHash(header.Hash(), query.Skip+1)[query.Skip] == query.Origin.Hash {
+ query.Origin.Hash = header.Hash()
+ } else {
+ unknown = true
+ }
} else {
unknown = true
}
- } else {
- unknown = true
}
case query.Reverse:
// Number based traversal towards the genesis block