Skip to content

Commit 842888a

Browse files
committed
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 <[email protected]>
1 parent 9e7529c commit 842888a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

device/noise-protocol.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ type MessageCookieReply struct {
116116
Cookie [blake2s.Size128 + poly1305.TagSize]byte
117117
}
118118

119-
var errMessageTooShort = errors.New("message too short")
119+
var errMessageLengthMismatch = errors.New("message length mismatch")
120120

121121
func (msg *MessageInitiation) unmarshal(b []byte) error {
122-
if len(b) < MessageInitiationSize {
123-
return errMessageTooShort
122+
if len(b) != MessageInitiationSize {
123+
return errMessageLengthMismatch
124124
}
125125

126126
msg.Type = binary.LittleEndian.Uint32(b)
@@ -135,8 +135,8 @@ func (msg *MessageInitiation) unmarshal(b []byte) error {
135135
}
136136

137137
func (msg *MessageResponse) unmarshal(b []byte) error {
138-
if len(b) < MessageResponseSize {
139-
return errMessageTooShort
138+
if len(b) != MessageResponseSize {
139+
return errMessageLengthMismatch
140140
}
141141

142142
msg.Type = binary.LittleEndian.Uint32(b)
@@ -151,8 +151,8 @@ func (msg *MessageResponse) unmarshal(b []byte) error {
151151
}
152152

153153
func (msg *MessageCookieReply) unmarshal(b []byte) error {
154-
if len(b) < MessageCookieReplySize {
155-
return errMessageTooShort
154+
if len(b) != MessageCookieReplySize {
155+
return errMessageLengthMismatch
156156
}
157157

158158
msg.Type = binary.LittleEndian.Uint32(b)

0 commit comments

Comments
 (0)