From 7b9be9377f61f7bb5d174614c36c294a3b730c78 Mon Sep 17 00:00:00 2001 From: lanrenwo Date: Fri, 8 Sep 2023 20:33:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DlogAudit=E7=9A=84panic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/handler/payload_access_audit.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/server/handler/payload_access_audit.go b/server/handler/payload_access_audit.go index e703c1c..99efa24 100644 --- a/server/handler/payload_access_audit.go +++ b/server/handler/payload_access_audit.go @@ -103,10 +103,10 @@ func logAuditBatch() { // 解析IP包的数据 func logAudit(userName string, pl *sessdata.Payload) { defer func() { - putPayload(pl) if err := recover(); err != nil { base.Error("logAudit is panic: ", err, "\n", string(debug.Stack()), "\n", pl.Data) } + putPayload(pl) }() if !(pl.LType == sessdata.LTypeIPData && pl.PType == 0x00) { @@ -125,19 +125,16 @@ func logAudit(userName string, pl *sessdata.Payload) { default: return } - - 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 + // 修复 panic: runtime error: index out of range [2] / range [3] ipPl := waterutil.IPv4Payload(pl.Data) - if len(ipPl) < 3 { - base.Error("ipPl len < 3", pl.Data) + if len(ipPl) < 4 { + base.Error("ipPl len < 4", ipPl, pl.Data) return } ipPort := (uint16(ipPl[2]) << 8) | uint16(ipPl[3]) - + ipSrc := waterutil.IPv4Source(pl.Data) + ipDst := waterutil.IPv4Destination(pl.Data) b := getByte51() key := *b copy(key[:16], ipSrc) @@ -193,7 +190,6 @@ func logAudit(userName string, pl *sessdata.Payload) { AccessProto: accessProto, Info: info, } - select { case logBatch.LogChan <- audit: default: From 8e843d5eaed90c32323244651cc1d09bd5871238 Mon Sep 17 00:00:00 2001 From: lanrenwo Date: Fri, 8 Sep 2023 21:01:03 +0800 Subject: [PATCH 2/2] Update payload_access_audit.go --- server/handler/payload_access_audit.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/handler/payload_access_audit.go b/server/handler/payload_access_audit.go index 99efa24..a3cc0c2 100644 --- a/server/handler/payload_access_audit.go +++ b/server/handler/payload_access_audit.go @@ -125,8 +125,7 @@ func logAudit(userName string, pl *sessdata.Payload) { default: return } - // ipPort := waterutil.IPv4DestinationPort(pl.Data) - // 修复 panic: runtime error: index out of range [2] / range [3] + // IP报文只包含头部信息时, 则打印LOG,并退出 ipPl := waterutil.IPv4Payload(pl.Data) if len(ipPl) < 4 { base.Error("ipPl len < 4", ipPl, pl.Data)