From 73b338aa6dbca0dfab73fe9d185774707b2e06e9 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 28 Aug 2018 21:17:00 +0300 Subject: [PATCH] fix nil pointer dereference in copyRPC --- comm.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/comm.go b/comm.go index 9c7487a..f679fc4 100644 --- a/comm.go +++ b/comm.go @@ -124,17 +124,20 @@ func rpcWithControl(msgs []*pb.Message, } func copyRPC(rpc *RPC) *RPC { - return &RPC{ + res := &RPC{ RPC: pb.RPC{ Subscriptions: rpc.Subscriptions, Publish: rpc.Publish, - Control: &pb.ControlMessage{ - Ihave: rpc.Control.Ihave, - Iwant: rpc.Control.Iwant, - Graft: rpc.Control.Graft, - Prune: rpc.Control.Prune, - }, }, from: rpc.from, } + if rpc.Control != nil { + res.Control = &pb.ControlMessage{ + Ihave: rpc.Control.Ihave, + Iwant: rpc.Control.Iwant, + Graft: rpc.Control.Graft, + Prune: rpc.Control.Prune, + } + } + return res }