Skip to content

Commit da795f9

Browse files
committed
ethernet{,_test}: fix slice bounds out of range panic found by go-fuzz, add test with crasher
1 parent c03dde9 commit da795f9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ethernet.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ func (f *Frame) UnmarshalBinary(b []byte) error {
142142
// values are detected
143143
et := EtherType(binary.BigEndian.Uint16(b[n-2 : n]))
144144
for ; et == EtherTypeVLAN; n += 4 {
145-
// 2 or more bytes must remain for valid VLAN tag
146-
if len(b[n:]) < 2 {
145+
// 4 or more bytes must remain for valid VLAN tag and EtherType
146+
if len(b[n:]) < 4 {
147147
return io.ErrUnexpectedEOF
148148
}
149149

ethernet_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func TestFrameUnmarshalBinary(t *testing.T) {
153153
0, 0, 0, 0, 0, 0,
154154
0x81, 0x00,
155155
0xff, 0xff,
156+
0x00, 0x00,
156157
},
157158
err: ErrInvalidVLAN,
158159
},
@@ -180,6 +181,11 @@ func TestFrameUnmarshalBinary(t *testing.T) {
180181
}, bytes.Repeat([]byte{0}, 37)...),
181182
err: io.ErrUnexpectedEOF,
182183
},
184+
{
185+
desc: "go-fuzz crasher: VLAN tag without enough bytes for trailing EtherType",
186+
b: []byte("190734863281\x81\x0032"),
187+
err: io.ErrUnexpectedEOF,
188+
},
183189
{
184190
desc: "0 VLANs detected, but 1 may have been present",
185191
b: bytes.Repeat([]byte{0}, 56),

0 commit comments

Comments
 (0)