device: make unmarshall length checks exact
This is already enforced in receive.go, but if these unmarshallers are to have error return values anyway, make them as explicit as possible. cherry picked from commit WireGuard/wireguard-go@842888ac5c Updates tailscale/corp#28879 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
19f7e29805
commit
ae0636254c
1 changed files with 7 additions and 7 deletions
|
|
@ -116,11 +116,11 @@ type MessageCookieReply struct {
|
||||||
Cookie [blake2s.Size128 + poly1305.TagSize]byte
|
Cookie [blake2s.Size128 + poly1305.TagSize]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
var errMessageTooShort = errors.New("message too short")
|
var errMessageLengthMismatch = errors.New("message length mismatch")
|
||||||
|
|
||||||
func (msg *MessageInitiation) unmarshal(b []byte) error {
|
func (msg *MessageInitiation) unmarshal(b []byte) error {
|
||||||
if len(b) < MessageInitiationSize {
|
if len(b) != MessageInitiationSize {
|
||||||
return errMessageTooShort
|
return errMessageLengthMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Type = binary.LittleEndian.Uint32(b)
|
msg.Type = binary.LittleEndian.Uint32(b)
|
||||||
|
|
@ -135,8 +135,8 @@ func (msg *MessageInitiation) unmarshal(b []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *MessageResponse) unmarshal(b []byte) error {
|
func (msg *MessageResponse) unmarshal(b []byte) error {
|
||||||
if len(b) < MessageResponseSize {
|
if len(b) != MessageResponseSize {
|
||||||
return errMessageTooShort
|
return errMessageLengthMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Type = binary.LittleEndian.Uint32(b)
|
msg.Type = binary.LittleEndian.Uint32(b)
|
||||||
|
|
@ -151,8 +151,8 @@ func (msg *MessageResponse) unmarshal(b []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *MessageCookieReply) unmarshal(b []byte) error {
|
func (msg *MessageCookieReply) unmarshal(b []byte) error {
|
||||||
if len(b) < MessageCookieReplySize {
|
if len(b) != MessageCookieReplySize {
|
||||||
return errMessageTooShort
|
return errMessageLengthMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Type = binary.LittleEndian.Uint32(b)
|
msg.Type = binary.LittleEndian.Uint32(b)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue