修复空载荷包越界 panic 杀死数据面任务

对端构造的零载荷包(头部长度恰好等于 HEAD_LENGTH)会使
TunDataInbound/InternalNatInbound 的 data[0] 索引越界 panic,
tokio 任务终止后连接永久静默死亡。两处 send 均增加空切片检查,
畸形包静默丢弃。补充空包/短包不 panic 的测试。
This commit is contained in:
lbl
2026-08-20 21:48:24 +08:00
parent b0db6c9659
commit 6489237233
2 changed files with 38 additions and 2 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ impl InternalNatInbound {
})
}
pub async fn send(&self, data: &[u8], net: &NetworkAddr) -> anyhow::Result<()> {
if data[0] >> 4 != 4 {
if data.is_empty() || data[0] >> 4 != 4 {
return Ok(());
}
let Some(ipv4) = Ipv4Packet::new(data) else {