Skip to content

Commit

Permalink
fix: call validatePathAttributeFlags after parsing and setting path a…
Browse files Browse the repository at this point in the history
…ttribute length
  • Loading branch information
floatingstatic committed Oct 30, 2023
1 parent 1b975be commit 286c887
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10029,9 +10029,6 @@ func (p *PathAttribute) DecodeFromBytes(data []byte, options ...*MarshallingOpti
}
p.Flags = BGPAttrFlag(data[0])
p.Type = BGPAttrType(data[1])
if eMsg := validatePathAttributeFlags(p.Type, p.Flags); eMsg != "" {
return nil, NewMessageError(eCode, BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR, data, eMsg)
}

if p.Flags&BGP_ATTR_FLAG_EXTENDED_LENGTH != 0 {
if len(data) < 4 {
Expand All @@ -10050,6 +10047,10 @@ func (p *PathAttribute) DecodeFromBytes(data []byte, options ...*MarshallingOpti
return nil, NewMessageError(eCode, eSubCode, data, "attribute value length is short")
}

if eMsg := validatePathAttributeFlags(p.Type, p.Flags); eMsg != "" {
return nil, NewMessageError(eCode, BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR, data, eMsg)
}

return data[:p.Length], nil
}

Expand Down

0 comments on commit 286c887

Please sign in to comment.