aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2025-05-15 16:48:14 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2025-05-15 16:48:14 +0200
commit842888ac5c93ccc5ee6344eceaadf783fcf1e243 (patch)
tree607e0f9c600dece9211b011a6bdcaffa45c3c0e9
parentdevice: reduce RoutineHandshake allocations (diff)
downloadwireguard-go-842888ac5c93ccc5ee6344eceaadf783fcf1e243.tar.xz
wireguard-go-842888ac5c93ccc5ee6344eceaadf783fcf1e243.zip
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. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--device/noise-protocol.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/device/noise-protocol.go b/device/noise-protocol.go
index 12368ec..5f713ee 100644
--- a/device/noise-protocol.go
+++ b/device/noise-protocol.go
@@ -116,11 +116,11 @@ type MessageCookieReply struct {
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 {
- if len(b) < MessageInitiationSize {
- return errMessageTooShort
+ if len(b) != MessageInitiationSize {
+ return errMessageLengthMismatch
}
msg.Type = binary.LittleEndian.Uint32(b)
@@ -135,8 +135,8 @@ func (msg *MessageInitiation) unmarshal(b []byte) error {
}
func (msg *MessageResponse) unmarshal(b []byte) error {
- if len(b) < MessageResponseSize {
- return errMessageTooShort
+ if len(b) != MessageResponseSize {
+ return errMessageLengthMismatch
}
msg.Type = binary.LittleEndian.Uint32(b)
@@ -151,8 +151,8 @@ func (msg *MessageResponse) unmarshal(b []byte) error {
}
func (msg *MessageCookieReply) unmarshal(b []byte) error {
- if len(b) < MessageCookieReplySize {
- return errMessageTooShort
+ if len(b) != MessageCookieReplySize {
+ return errMessageLengthMismatch
}
msg.Type = binary.LittleEndian.Uint32(b)