mirror of
https://github.com/netsampler/goflow2.git
synced 2024-05-06 15:54:52 +00:00
bugfix: check etype size before decoding (#252)
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
@ -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
|
||||
|
Reference in New Issue
Block a user