fix: 增强参数检查

This commit is contained in:
zhengqi committed 2022-09-18 23:02:04 +08:00
1 parent 32937ca587
commit 330f26a234
4 files changed
+31 -7

No files matched your search

+3 -3
View File
@@ -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
}
+5 -1
View File
@@ -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 {
+19 -3
View File
@@ -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)
+4
View File
@@ -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)