From 330f26a234b88dcb64843c95d2055b7092feaba0 Mon Sep 17 00:00:00 2001 From: zhengqi <709030194@qq.com> Date: Sun, 18 Sep 2022 23:02:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=BC=BA=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lsdb/Lsdb.go | 6 +++--- mlsrcmd/mlsr.go | 6 +++++- route/NamePrefixTable.go | 22 +++++++++++++++++++--- route/RoutingTable.go | 4 ++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lsdb/Lsdb.go b/lsdb/Lsdb.go index 0b54fda..909f1e1 100644 --- a/lsdb/Lsdb.go +++ b/lsdb/Lsdb.go @@ -153,7 +153,7 @@ func (l *Lsdb) Init(mc *common.MlsrConfig, ms *MlsrScheduler, if args[2] != nil { originRouter, ok = args[2].(*component.Identifier) - if !ok { + if !ok || originRouter == nil { common2.LogError("originRouter conversion failed.") return } @@ -826,7 +826,7 @@ func (l *Lsdb) ExpressInterest(interestName *component.Identifier, var ok bool if args[0] != nil { data, ok = args[0].(*packet.Data) - if !ok { + if !ok || data == nil { common2.LogError("data conversion failed.") return } @@ -858,7 +858,7 @@ func (l *Lsdb) ExpressInterest(interestName *component.Identifier, var ok bool if args[0] != nil { buffer, ok = args[0].([]byte) - if !ok { + if !ok || buffer == nil { common2.LogError("buffer conversion failed.") return } diff --git a/mlsrcmd/mlsr.go b/mlsrcmd/mlsr.go index 5765868..ab13b90 100644 --- a/mlsrcmd/mlsr.go +++ b/mlsrcmd/mlsr.go @@ -123,7 +123,11 @@ func (m *Mlsr) Init(face *logicface.DummyClientLogicFace, scheduler *lsdb.MlsrSc bindHelloFunc := func(args ...interface{}) { common2.LogInfo("Mlsr.bindHelloFunc") // Hello协议收到有效Data包,解析其参数为邻居 - neighbor := args[0].(*component.Identifier) + neighbor, ok := args[0].(*component.Identifier) + if !ok || neighbor == nil { + common2.LogError("Invalid Identifier") + return + } // 查看本机是否已知道此路由器 adjInfo := m.m_adjacencyList.FindAdjacencyByRouterIdentifier(neighbor) if adjInfo != nil { diff --git a/route/NamePrefixTable.go b/route/NamePrefixTable.go index b84cd9d..3bb45d8 100644 --- a/route/NamePrefixTable.go +++ b/route/NamePrefixTable.go @@ -86,7 +86,11 @@ func (t *NamePrefixTable) Init(ownRouterName *component.Identifier, // 监听路由表的修改,触发NPT表修改 bindRoutingChangeFunc := func(args ...interface{}) { common2.LogInfo("NamePrefixTable bindRoutingChangeFunc.") - entrys := args[0].([]*RoutingTableEntry) + entrys, ok := args[0].([]*RoutingTableEntry) + if !ok || entrys == nil { + common2.LogError("NamePrefixTable Invalid Entry") + return + } t.UpdateWithNewRoute(entrys) } t.m_afterRoutingChangeConnection = afterRoutingChangeSignal.Connect(bindRoutingChangeFunc) @@ -96,14 +100,26 @@ func (t *NamePrefixTable) Init(ownRouterName *component.Identifier, common2.LogInfo("NamePrefixTable bindLsdbModifiedFunc.") // 获取四个参数 ilsa := args[0].(lsa.ILsa) + if ilsa == nil { + common2.LogError("Invalid lsa") + return + } updateType := args[1].(lsdb.LsdbUpdate) common2.LogInfo("NamePrefixTable bindLsdbModifiedFunc lsa: ", ilsa.GetOriginRouter().ToUri()) common2.LogInfo("NamePrefixTable bindLsdbModifiedFunc updateType: ", updateType) namesToAdd := []*component.Identifier{} namesToRemove := []*component.Identifier{} if updateType == lsdb.UPDATED { - namesToAdd = args[2].([]*component.Identifier) - namesToRemove = args[3].([]*component.Identifier) + namesToAdd, ok := args[2].([]*component.Identifier) + if !ok || namesToAdd == nil { + common2.LogError("Invalid namesToAdd") + return + } + namesToRemove, ok = args[3].([]*component.Identifier) + if !ok || namesToRemove == nil { + common2.LogError("Invalid namesToRemove") + return + } } // 执行更新操作 t.UpdateFromLsdb(ilsa, updateType, namesToAdd, namesToRemove) diff --git a/route/RoutingTable.go b/route/RoutingTable.go index 4c0a77e..1aff941 100644 --- a/route/RoutingTable.go +++ b/route/RoutingTable.go @@ -98,6 +98,10 @@ func (t *RoutingTable) Init(mc *common.MlsrConfig, bindFunc := func(args ...interface{}) { // 获取四个参数 ilsa := args[0].(lsa.ILsa) + if ilsa == nil { + common2.LogError("Invalid lsa") + return + } updateType := args[1].(lsdb.LsdbUpdate) common2.LogInfo("RoutingTable.bindFunc: ", ilsa.GetOriginRouter().ToUri(), " ", updateType)