From 0558066261625d0f4e7d5c118a0efd4238d24715 Mon Sep 17 00:00:00 2001 From: Sergey Elantsev Date: Sun, 20 Dec 2020 18:13:10 +0300 Subject: fixed possible crashes on parsing of bgp messages --- pkg/packet/bgp/sr_policy.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pkg/packet/bgp/sr_policy.go') diff --git a/pkg/packet/bgp/sr_policy.go b/pkg/packet/bgp/sr_policy.go index e7baa069..cdd89db2 100644 --- a/pkg/packet/bgp/sr_policy.go +++ b/pkg/packet/bgp/sr_policy.go @@ -742,9 +742,12 @@ func (t *TunnelEncapSubTLVSRSegmentList) DecodeFromBytes(data []byte) error { if err != nil { return NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, err.Error()) } + if len(value) < 1 { + return NewMessageError(BGP_ERROR_MESSAGE_HEADER_ERROR, BGP_ERROR_SUB_BAD_MESSAGE_LENGTH, nil, "Malformed BGP message") + } // Skip reserved byte to access inner SubTLV type value = value[1:] - segments := make([]TunnelEncapSubTLVInterface, 0) + var segments []TunnelEncapSubTLVInterface p := 0 for p < t.TunnelEncapSubTLV.Len()-4 { var segment TunnelEncapSubTLVInterface -- cgit v1.2.3