Skip to content

Commit

Permalink
Panic if buffer length >= 4 GiB, rather than passing an incorrect len…
Browse files Browse the repository at this point in the history
…gth.
  • Loading branch information
qwandor authored and DeathWish5 committed Jun 6, 2024
1 parent 9a467d7 commit ffa8ee2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use alloc::boxed::Box;
use bitflags::bitflags;
#[cfg(test)]
use core::cmp::min;
use core::convert::TryInto;
use core::hint::spin_loop;
use core::mem::{size_of, take};
#[cfg(test)]
Expand Down Expand Up @@ -717,7 +718,7 @@ impl Descriptor {
unsafe {
self.addr = H::share(buf, direction) as u64;
}
self.len = buf.len() as u32;
self.len = buf.len().try_into().unwrap();
self.flags = extra_flags
| match direction {
BufferDirection::DeviceToDriver => DescFlags::WRITE,
Expand Down Expand Up @@ -957,7 +958,7 @@ pub(crate) fn fake_read_write_queue<const QUEUE_SIZE: usize>(
}

// Mark the buffer as used.
(*used_ring).ring[next_slot as usize].id = head_descriptor_index as u32;
(*used_ring).ring[next_slot as usize].id = head_descriptor_index.into();
(*used_ring).ring[next_slot as usize].len = (input_length + output.len()) as u32;
(*used_ring).idx.fetch_add(1, Ordering::AcqRel);
}
Expand Down

0 comments on commit ffa8ee2

Please sign in to comment.