Skip to content

Commit

Permalink
Ensure rx buffer slice length matches recvd len
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlamb-gh committed Oct 16, 2023
1 parent ba8c358 commit 90130e1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions firmware/src/net/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down

0 comments on commit 90130e1

Please sign in to comment.