mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Update message.go
This commit is contained in:
parent
31d5d82ce5
commit
064b6efc53
1 changed files with 9 additions and 1 deletions
|
|
@ -242,10 +242,18 @@ func ExpectMsg(r MsgReader, code uint64, content interface{}) error {
|
|||
if int(msg.Size) != len(contentEnc) {
|
||||
return fmt.Errorf("message size mismatch: got %d, want %d", msg.Size, len(contentEnc))
|
||||
}
|
||||
actualContent, err := io.ReadAll(msg.Payload)
|
||||
// Read only up to the declared message size (+1 to detect overlong payloads).
|
||||
limit := int64(msg.Size)
|
||||
actualContent, err := io.ReadAll(io.LimitReader(msg.Payload, limit+1))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if int64(len(actualContent)) > limit {
|
||||
return fmt.Errorf("message payload longer than declared size: got at least %d bytes, declared %d", len(actualContent), msg.Size)
|
||||
}
|
||||
if int64(len(actualContent)) < limit {
|
||||
return fmt.Errorf("message payload shorter than declared size: got %d bytes, declared %d", len(actualContent), msg.Size)
|
||||
}
|
||||
if !bytes.Equal(actualContent, contentEnc) {
|
||||
return fmt.Errorf("message payload mismatch:\ngot: %x\nwant: %x", actualContent, contentEnc)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue