From 3313e8f8d63e0b502d6324d4d900f32776e11130 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Wed, 2 Sep 2015 21:45:16 +0900 Subject: server: guard against nil pointer dereference non-route-server-client peers don't have local rib. Reported-by: Pavel Odintsov Signed-off-by: ISHIDA Wataru --- server/server.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/server.go b/server/server.go index 458703fe..c5c57ddf 100644 --- a/server/server.go +++ b/server/server.go @@ -1472,6 +1472,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { if err != nil { break } + result := &GrpcResponse{} reqApplyPolicy := grpcReq.Data.(*api.ApplyPolicy) reqPolicyMap := server.policyMap applyPolicy := &peer.conf.ApplyPolicy.ApplyPolicyConfig @@ -1509,11 +1510,15 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_DISTRIBUTE { peer.setPolicy(reqPolicyMap) } else { - loc := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()] - loc.setPolicy(peer, reqPolicyMap) + loc, ok := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()] + if ok { + loc.setPolicy(peer, reqPolicyMap) + } else { + result.ResponseErr = fmt.Errorf("no local rib for %s", peer.conf.NeighborConfig.NeighborAddress.String()) + } } - grpcReq.ResponseCh <- &GrpcResponse{} + grpcReq.ResponseCh <- result close(grpcReq.ResponseCh) case REQ_POLICY_PREFIXES, REQ_POLICY_NEIGHBORS, REQ_POLICY_ASPATHS, -- cgit v1.2.3