Skip to content

Commit

Permalink
bugfix: check etype size before decoding (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
lspgn committed Dec 13, 2023
1 parent 1a5d58e commit 3f017c4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion producer/proto/producer_sf.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,37 @@ func ParseICMPv6(offset int, flowMessage *ProtoProducerMessage, data []byte) (ne
}

func IsMPLS(etherType []byte) bool {
if len(etherType) != 2 {
return false
}
return etherType[0] == 0x88 && etherType[1] == 0x47
}

func Is8021Q(etherType []byte) bool {
if len(etherType) != 2 {
return false
}
return etherType[0] == 0x81 && etherType[1] == 0x0
}

func IsIPv4(etherType []byte) bool {
if len(etherType) != 2 {
return false
}
return etherType[0] == 0x8 && etherType[1] == 0x0
}

func IsIPv6(etherType []byte) bool {
if len(etherType) != 2 {
return false
}
return etherType[0] == 0x86 && etherType[1] == 0xdd
}

func IsARP(etherType []byte) bool {
if len(etherType) != 2 {
return false
}
return etherType[0] == 0x8 && etherType[1] == 0x6
}

Expand All @@ -238,6 +253,10 @@ func ParseEthernetHeader(flowMessage *ProtoProducerMessage, data []byte, config
return err
}

if len(etherType) != 2 {
return nil
}

encap := true
iterations := 0
for encap && iterations <= 1 {
Expand Down Expand Up @@ -371,7 +390,9 @@ func ParseEthernetHeader(flowMessage *ProtoProducerMessage, data []byte, config
iterations++
}

flowMessage.Etype = uint32(binary.BigEndian.Uint16(etherType[0:2]))
if len(etherType) >= 2 {
flowMessage.Etype = uint32(binary.BigEndian.Uint16(etherType[0:2]))
}
flowMessage.Proto = uint32(nextHeader)

return nil
Expand Down

0 comments on commit 3f017c4

Please sign in to comment.