Merge pull request #270 from lanrenwo/dev

修复logAudit的panic
This commit is contained in:
bjdgyc 2023-09-12 08:40:50 +08:00 committed by GitHub
commit c6b85c7d66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 11 deletions

View File

@ -103,10 +103,10 @@ func logAuditBatch() {
// 解析IP包的数据 // 解析IP包的数据
func logAudit(userName string, pl *sessdata.Payload) { func logAudit(userName string, pl *sessdata.Payload) {
defer func() { defer func() {
putPayload(pl)
if err := recover(); err != nil { if err := recover(); err != nil {
base.Error("logAudit is panic: ", err, "\n", string(debug.Stack()), "\n", pl.Data) base.Error("logAudit is panic: ", err, "\n", string(debug.Stack()), "\n", pl.Data)
} }
putPayload(pl)
}() }()
if !(pl.LType == sessdata.LTypeIPData && pl.PType == 0x00) { if !(pl.LType == sessdata.LTypeIPData && pl.PType == 0x00) {
@ -125,19 +125,15 @@ func logAudit(userName string, pl *sessdata.Payload) {
default: default:
return return
} }
// IP报文只包含头部信息时, 则打印LOG并退出
ipSrc := waterutil.IPv4Source(pl.Data)
ipDst := waterutil.IPv4Destination(pl.Data)
// ipPort := waterutil.IPv4DestinationPort(pl.Data)
// 修复 panic: runtime error: index out of range [2] with length 2
ipPl := waterutil.IPv4Payload(pl.Data) ipPl := waterutil.IPv4Payload(pl.Data)
if len(ipPl) < 3 { if len(ipPl) < 4 {
base.Error("ipPl len < 3", pl.Data) base.Error("ipPl len < 4", ipPl, pl.Data)
return return
} }
ipPort := (uint16(ipPl[2]) << 8) | uint16(ipPl[3]) ipPort := (uint16(ipPl[2]) << 8) | uint16(ipPl[3])
ipSrc := waterutil.IPv4Source(pl.Data)
ipDst := waterutil.IPv4Destination(pl.Data)
b := getByte51() b := getByte51()
key := *b key := *b
copy(key[:16], ipSrc) copy(key[:16], ipSrc)
@ -193,7 +189,6 @@ func logAudit(userName string, pl *sessdata.Payload) {
AccessProto: accessProto, AccessProto: accessProto,
Info: info, Info: info,
} }
select { select {
case logBatch.LogChan <- audit: case logBatch.LogChan <- audit:
default: default: