aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/rlpx.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-04 23:39:04 +0800
committerFelix Lange <fjl@twurst.com>2015-03-04 23:42:01 +0800
commit429828cd9205a8db0024652fd9da96cfbdaeae86 (patch)
treefac6621e110c9fdb038cf12e164ccf98e439295b /p2p/rlpx.go
parent22659a7feaf4e939a33762c3f83b43d8bec757db (diff)
downloadgo-tangerine-429828cd9205a8db0024652fd9da96cfbdaeae86.tar
go-tangerine-429828cd9205a8db0024652fd9da96cfbdaeae86.tar.gz
go-tangerine-429828cd9205a8db0024652fd9da96cfbdaeae86.tar.bz2
go-tangerine-429828cd9205a8db0024652fd9da96cfbdaeae86.tar.lz
go-tangerine-429828cd9205a8db0024652fd9da96cfbdaeae86.tar.xz
go-tangerine-429828cd9205a8db0024652fd9da96cfbdaeae86.tar.zst
go-tangerine-429828cd9205a8db0024652fd9da96cfbdaeae86.zip
p2p: reject messages that cannot be written as simple RLPx frames
Until chunked frames are implemented we cannot send messages with a size overflowing uint24.
Diffstat (limited to 'p2p/rlpx.go')
-rw-r--r--p2p/rlpx.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/p2p/rlpx.go b/p2p/rlpx.go
index 166bbb5e6..6b533e275 100644
--- a/p2p/rlpx.go
+++ b/p2p/rlpx.go
@@ -19,6 +19,8 @@ var (
// sixteen zero bytes
zero16 = make([]byte, 16)
+
+ maxUint24 = ^uint32(0) >> 8
)
// rlpxFrameRW implements a simplified version of RLPx framing.
@@ -64,6 +66,9 @@ func (rw *rlpxFrameRW) WriteMsg(msg Msg) error {
// write header
headbuf := make([]byte, 32)
fsize := uint32(len(ptype)) + msg.Size
+ if fsize > maxUint24 {
+ return errors.New("message size overflows uint24")
+ }
putInt24(fsize, headbuf) // TODO: check overflow
copy(headbuf[3:], zeroHeader)
rw.enc.XORKeyStream(headbuf[:16], headbuf[:16]) // first half is now encrypted