From a168c96a935e1065d78c24bdbc9cb37de9b418ae Mon Sep 17 00:00:00 2001
From: lanrenwo <phpcleps@gmail.com>
Date: Fri, 1 Sep 2023 18:10:20 +0800
Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8DsniNewParser=E7=9A=84pani?=
 =?UTF-8?q?c?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 server/handler/payload_tcp_parser.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/server/handler/payload_tcp_parser.go b/server/handler/payload_tcp_parser.go
index 6d3c4cc..f2e1c31 100644
--- a/server/handler/payload_tcp_parser.go
+++ b/server/handler/payload_tcp_parser.go
@@ -32,6 +32,9 @@ func sniNewParser(b []byte) (uint8, string) {
 	if len(b) < 2 || b[0] != 0x16 || b[1] != 0x03 {
 		return acc_proto_tcp, ""
 	}
+	if len(b) < 6 {
+		return acc_proto_tcp, ""
+	}	
 	rest := b[5:]
 	restLen := len(rest)
 	if restLen == 0 {

From 2af2d273e4725284f255a4f8c2dd486dee7502c0 Mon Sep 17 00:00:00 2001
From: lanrenwo <phpcleps@gmail.com>
Date: Sat, 2 Sep 2023 10:44:47 +0800
Subject: [PATCH 2/6] =?UTF-8?q?=E7=AE=80=E5=8C=96sniNewParser=E4=BB=A3?=
 =?UTF-8?q?=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 server/handler/payload_tcp_parser.go | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/server/handler/payload_tcp_parser.go b/server/handler/payload_tcp_parser.go
index f2e1c31..bbb933e 100644
--- a/server/handler/payload_tcp_parser.go
+++ b/server/handler/payload_tcp_parser.go
@@ -29,10 +29,7 @@ func onTCP(payload []byte) (uint8, string) {
 }
 
 func sniNewParser(b []byte) (uint8, string) {
-	if len(b) < 2 || b[0] != 0x16 || b[1] != 0x03 {
-		return acc_proto_tcp, ""
-	}
-	if len(b) < 6 {
+	if len(b) < 6 || b[0] != 0x16 || b[1] != 0x03 {
 		return acc_proto_tcp, ""
 	}	
 	rest := b[5:]

From 7651b69ed636649161c36f0613719d69960b4b6c Mon Sep 17 00:00:00 2001
From: lanrenwo <phpcleps@gmail.com>
Date: Sat, 2 Sep 2023 10:46:01 +0800
Subject: [PATCH 3/6] =?UTF-8?q?=E5=88=A0=E9=99=A4sniNewParser=E5=A4=9A?=
 =?UTF-8?q?=E4=BD=99=E7=9A=84=E7=A9=BA=E6=A0=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 server/handler/payload_tcp_parser.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/handler/payload_tcp_parser.go b/server/handler/payload_tcp_parser.go
index bbb933e..95c9a0d 100644
--- a/server/handler/payload_tcp_parser.go
+++ b/server/handler/payload_tcp_parser.go
@@ -31,7 +31,7 @@ func onTCP(payload []byte) (uint8, string) {
 func sniNewParser(b []byte) (uint8, string) {
 	if len(b) < 6 || b[0] != 0x16 || b[1] != 0x03 {
 		return acc_proto_tcp, ""
-	}	
+	}
 	rest := b[5:]
 	restLen := len(rest)
 	if restLen == 0 {

From f6980261d456531f69fd8ab92437539d75dd344d Mon Sep 17 00:00:00 2001
From: lanrenwo <phpcleps@gmail.com>
Date: Sun, 3 Sep 2023 11:18:52 +0800
Subject: [PATCH 4/6] =?UTF-8?q?logAudit=E5=BC=95=E5=85=A5recover,=20?=
 =?UTF-8?q?=E9=98=B2=E6=AD=A2=E4=B8=BB=E7=A8=8B=E5=BA=8F=E5=B4=A9=E6=BA=83?=
 =?UTF-8?q?.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 server/handler/payload_access_audit.go | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/server/handler/payload_access_audit.go b/server/handler/payload_access_audit.go
index 89f3450..e703c1c 100644
--- a/server/handler/payload_access_audit.go
+++ b/server/handler/payload_access_audit.go
@@ -3,6 +3,7 @@ package handler
 import (
 	"crypto/md5"
 	"encoding/binary"
+	"runtime/debug"
 	"time"
 
 	"github.com/bjdgyc/anylink/base"
@@ -101,7 +102,12 @@ func logAuditBatch() {
 
 // 解析IP包的数据
 func logAudit(userName string, pl *sessdata.Payload) {
-	defer putPayload(pl)
+	defer func() {
+		putPayload(pl)
+		if err := recover(); err != nil {
+			base.Error("logAudit is panic: ", err, "\n", string(debug.Stack()), "\n", pl.Data)
+		}
+	}()
 
 	if !(pl.LType == sessdata.LTypeIPData && pl.PType == 0x00) {
 		return

From 7b9be9377f61f7bb5d174614c36c294a3b730c78 Mon Sep 17 00:00:00 2001
From: lanrenwo <phpcleps@gmail.com>
Date: Fri, 8 Sep 2023 20:33:30 +0800
Subject: [PATCH 5/6] =?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 <phpcleps@gmail.com>
Date: Fri, 8 Sep 2023 21:01:03 +0800
Subject: [PATCH 6/6] 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)