Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bcc7e58caea0
Choose a base ref
...
head repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0d82444556dd
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Apr 14, 2020

  1. Fix packet buffer panic caused by large payload (#332)

    When packet buffer's payload buffer does not have enough contiguous
    window left, the ring buffer roll over uses an incorrect size
    causing the ring buffer pointer not resetting to the head.
    
    When the payload enqueued is larger than 1/2 of the payload ring
    buffer, this bug will cause the slice returned by
    `PacketBuffer::enqueue` to not match the requested size, and
    trigger `debug_assert` in debug profile or size mismatch panic in
    `copy_from_slice` when compiled in release profile.
    nbdd0121 authored Apr 14, 2020
    Copy the full SHA
    0d82444 View commit details
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/storage/packet_buffer.rs
12 changes: 10 additions & 2 deletions src/storage/packet_buffer.rs
Original file line number Diff line number Diff line change
@@ -96,8 +96,8 @@ impl<'a, 'b, H> PacketBuffer<'a, 'b, H> {
} else {
// Add padding to the end of the ring buffer so that the
// contiguous window is at the beginning of the ring buffer.
*self.metadata_ring.enqueue_one()? = PacketMetadata::padding(size);
self.payload_ring.enqueue_many(size);
*self.metadata_ring.enqueue_one()? = PacketMetadata::padding(contig_window);
self.payload_ring.enqueue_many(contig_window);
}
}

@@ -224,6 +224,14 @@ mod test {
assert_eq!(buffer.metadata_ring.len(), 0);
}

#[test]
fn test_padding_with_large_payload() {
let mut buffer = buffer();
assert!(buffer.enqueue(12, ()).is_ok());
assert!(buffer.dequeue().is_ok());
buffer.enqueue(12, ()).unwrap().copy_from_slice(b"abcdefghijkl");
}

#[test]
fn test_dequeue_with() {
let mut buffer = buffer();