From dc9e91fc910f4c5edbe2500e789f3514d3862218 Mon Sep 17 00:00:00 2001 From: nevermore <2541248912@qq.com> Date: Tue, 9 Jul 2024 23:31:26 +0800 Subject: [PATCH] fix index out of length --- src/server/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/server/mod.rs b/src/server/mod.rs index 7ce2382..54e13f3 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -530,6 +530,9 @@ impl<'a, V: VectorTrait> ModbusFrame<'a, V> { } self.frame_start = 6; } + if self.frame_start >= self.buf.len(){ + return Err(ErrorKind::FrameBroken); + } let unit = self.buf[self.frame_start]; let broadcast = unit == 0 || unit == 255; // some clients send broadcast to 0xff if !broadcast && unit != self.unit_id {