From 90130e165d08329d8f2d1753b7981bf50929aee6 Mon Sep 17 00:00:00 2001 From: Jon Lamb Date: Mon, 16 Oct 2023 11:10:18 -0700 Subject: [PATCH] Ensure rx buffer slice length matches recvd len --- firmware/src/net/eth.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/firmware/src/net/eth.rs b/firmware/src/net/eth.rs index eafe6c5..36f04d0 100644 --- a/firmware/src/net/eth.rs +++ b/firmware/src/net/eth.rs @@ -63,10 +63,11 @@ impl<'buf> Device for Eth<'buf> { match self.drv.next_packet() { Ok(Some(packet)) => { - if packet.len() as usize > self.rx_buffer.len() { + let pkt_len = packet.len() as usize; + if pkt_len > self.rx_buffer.len() { warn!( "Dropping rx packet, too big, len {}, cap {}", - packet.len(), + pkt_len, self.rx_buffer.len() ); packet.ignore().unwrap(); @@ -76,7 +77,7 @@ impl<'buf> Device for Eth<'buf> { None } else { Some(( - RxToken(&mut self.rx_buffer[..]), + RxToken(&mut self.rx_buffer[..pkt_len]), TxToken { phy: &mut self.drv, buf: self.tx_buffer,