Skip to content

Commit 2b2c0c2

Browse files
committed
devp2p -> DPT: fixed undefined array access in ETH._getStatusString() on malformed ETH/64 status msgs (triggered in client runs)
1 parent 9fe77d6 commit 2b2c0c2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/devp2p/src/dpt/ban-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ export class BanList {
1313
this.lru = new LRUCache({ max: 30000 }) // 10k should be enough (each peer obj can has 3 keys)
1414
}
1515

16-
add(obj: string | Buffer | PeerInfo, maxAge?: number) {
16+
add(obj: string | Buffer | PeerInfo, maxAge?: number) {
1717
for (const key of KBucket.getKeys(obj)) {
1818
this.lru.set(key, true, maxAge)
1919
debug(`Added peer ${formatLogId(key, verbose)}, size: ${this.lru.length}`)
2020
}
2121
}
2222

23-
has(obj: string | Buffer | PeerInfo): boolean {
23+
has(obj: string | Buffer | PeerInfo): boolean {
2424
return KBucket.getKeys(obj).some((key: string) => Boolean(this.lru.get(key)))
2525
}
2626
}

packages/devp2p/src/eth/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ export class ETH extends EventEmitter {
182182
verbose
183183
)}`
184184
if (this._version >= 64) {
185-
sStr += `, ForkHash: 0x${(status[5][0] as Buffer).toString('hex')}`
186-
sStr += `, ForkNext: ${buffer2int(status[5][1] as Buffer)}`
185+
sStr += `, ForkHash: 0x${status[5] ? '0x' + (status[5][0] as Buffer).toString('hex') : '-'}`
186+
sStr += `, ForkNext: ${status[5] ? buffer2int(status[5][1] as Buffer) : '-'}`
187187
}
188188
sStr += `]`
189189
return sStr

0 commit comments

Comments
 (0)