From c297c0b222445df27e8e0642cbddf91be9ca8eb4 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Sun, 1 Nov 2020 22:46:29 +0900 Subject: server: handle bogus addpath argument Signed-off-by: FUJITA Tomonori --- pkg/server/grpc_server.go | 3 +++ pkg/server/server_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'pkg') diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index 25c8495e..3a7121f7 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -310,6 +310,9 @@ func api2Path(resource api.TableType, path *api.Path, isWithdraw bool) (*table.P case *bgp.PathAttributeNextHop: nexthop = a.Value.String() case *bgp.PathAttributeMpReachNLRI: + if len(a.Value) == 0 { + return nil, fmt.Errorf("invalid mp reach attribute") + } nlri = a.Value[0] nexthop = a.Nexthop.String() default: diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 43d3dbf3..4c96203e 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -1559,3 +1559,36 @@ func TestDeleteVrf(t *testing.T) { } s.StopBgp(context.Background(), &api.StopBgpRequest{}) } + +func TestAddBogusPath(t *testing.T) { + ctx := context.Background() + s := runNewServer(1, "1.1.1.1", 10179) + + nlri, _ := ptypes.MarshalAny(&api.IPAddressPrefix{}) + + a, _ := ptypes.MarshalAny(&api.MpReachNLRIAttribute{}) + + _, err := s.AddPath(ctx, &api.AddPathRequest{ + Path: &api.Path{ + Family: &api.Family{Afi: api.Family_AFI_IP, Safi: api.Family_SAFI_UNICAST}, + Nlri: nlri, + Pattrs: []*any.Any{a}, + }, + }) + assert.NotNil(t, err) + + nlri, _ = ptypes.MarshalAny(&api.IPAddressPrefix{}) + + a, _ = ptypes.MarshalAny(&api.MpReachNLRIAttribute{ + Family: &api.Family{Afi: api.Family_AFI_IP, Safi: api.Family_SAFI_FLOW_SPEC_UNICAST}, + }) + + _, err = s.AddPath(ctx, &api.AddPathRequest{ + Path: &api.Path{ + Family: &api.Family{Afi: api.Family_AFI_IP, Safi: api.Family_SAFI_UNICAST}, + Nlri: nlri, + Pattrs: []*any.Any{a}, + }, + }) + assert.NotNil(t, err) +} -- cgit v1.2.3