fix unsound access in EvtBox
This commit is contained in:
parent
810c6af77a
commit
3dbd58f40e
3 changed files with 5 additions and 12 deletions
|
@ -24,7 +24,7 @@ heapless = "0.7.16"
|
||||||
|
|
||||||
bit_field = "0.10.2"
|
bit_field = "0.10.2"
|
||||||
stm32-device-signature = { version = "0.3.3", features = ["stm32wb5x"] }
|
stm32-device-signature = { version = "0.3.3", features = ["stm32wb5x"] }
|
||||||
bluetooth-hci-async = { version = "*", git = "https://github.com/OueslatiGhaith/bluetooth-hci", optional = true }
|
bluetooth-hci-async = { version = "*", git = "https://github.com/OueslatiGhaith/bluetooth-hci", features = ["version-5-0"], optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt"]
|
defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt"]
|
||||||
|
|
|
@ -70,9 +70,10 @@ impl hci::Controller for Ble {
|
||||||
self.tl_write(opcode.0, payload).await;
|
self.tl_write(opcode.0, payload).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn controller_read(&self) -> &[u8] {
|
async fn controller_read_into(&self, buf: &mut [u8]) {
|
||||||
let evt_box = self.tl_read().await;
|
let evt_box = self.tl_read().await;
|
||||||
|
let evt_serial = evt_box.serial();
|
||||||
|
|
||||||
evt_box.serial()
|
buf[..evt_serial.len()].copy_from_slice(evt_serial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,14 +106,6 @@ impl EvtBox {
|
||||||
Self { ptr }
|
Self { ptr }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn evt<'a>(&self) -> &'a [u8] {
|
|
||||||
unsafe {
|
|
||||||
let evt_packet = &(*self.ptr);
|
|
||||||
|
|
||||||
core::slice::from_raw_parts(evt_packet as *const _ as *const u8, core::mem::size_of::<EvtPacket>())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns information about the event
|
/// Returns information about the event
|
||||||
pub fn stub(&self) -> EvtStub {
|
pub fn stub(&self) -> EvtStub {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -137,7 +129,7 @@ impl EvtBox {
|
||||||
/// writes an underlying [`EvtPacket`] into the provided buffer.
|
/// writes an underlying [`EvtPacket`] into the provided buffer.
|
||||||
/// Returns the number of bytes that were written.
|
/// Returns the number of bytes that were written.
|
||||||
/// Returns an error if event kind is unknown or if provided buffer size is not enough.
|
/// Returns an error if event kind is unknown or if provided buffer size is not enough.
|
||||||
pub fn serial<'a>(&self) -> &'a [u8] {
|
pub fn serial<'a>(&'a self) -> &'a [u8] {
|
||||||
unsafe {
|
unsafe {
|
||||||
let evt_serial: *const EvtSerial = &(*self.ptr).evt_serial;
|
let evt_serial: *const EvtSerial = &(*self.ptr).evt_serial;
|
||||||
let evt_serial_buf: *const u8 = evt_serial.cast();
|
let evt_serial_buf: *const u8 = evt_serial.cast();
|
||||||
|
|
Loading…
Reference in a new issue