diff options
| author | goueslati <[email protected]> | 2023-06-22 15:59:03 +0100 |
|---|---|---|
| committer | goueslati <[email protected]> | 2023-06-22 15:59:03 +0100 |
| commit | 3dbd58f40e07eb4b5d41a671aec0fe71ac8c4b34 (patch) | |
| tree | 5ee7c029fe6c6cac5ac525b07647cf92d5d4644d | |
| parent | 810c6af77af037a658186f8b102980ee84164a05 (diff) | |
fix unsound access in `EvtBox`
| -rw-r--r-- | embassy-stm32-wpan/Cargo.toml | 2 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/ble.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/evt.rs | 10 |
3 files changed, 5 insertions, 12 deletions
diff --git a/embassy-stm32-wpan/Cargo.toml b/embassy-stm32-wpan/Cargo.toml index fda4189ca..3659d7135 100644 --- a/embassy-stm32-wpan/Cargo.toml +++ b/embassy-stm32-wpan/Cargo.toml | |||
| @@ -24,7 +24,7 @@ heapless = "0.7.16" | |||
| 24 | 24 | ||
| 25 | bit_field = "0.10.2" | 25 | bit_field = "0.10.2" |
| 26 | stm32-device-signature = { version = "0.3.3", features = ["stm32wb5x"] } | 26 | stm32-device-signature = { version = "0.3.3", features = ["stm32wb5x"] } |
| 27 | bluetooth-hci-async = { version = "*", git = "https://github.com/OueslatiGhaith/bluetooth-hci", optional = true } | 27 | bluetooth-hci-async = { version = "*", git = "https://github.com/OueslatiGhaith/bluetooth-hci", features = ["version-5-0"], optional = true } |
| 28 | 28 | ||
| 29 | [features] | 29 | [features] |
| 30 | defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt"] | 30 | defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt"] |
diff --git a/embassy-stm32-wpan/src/ble.rs b/embassy-stm32-wpan/src/ble.rs index 297ee4cdf..04acf0aff 100644 --- a/embassy-stm32-wpan/src/ble.rs +++ b/embassy-stm32-wpan/src/ble.rs | |||
| @@ -70,9 +70,10 @@ impl hci::Controller for Ble { | |||
| 70 | self.tl_write(opcode.0, payload).await; | 70 | self.tl_write(opcode.0, payload).await; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | async fn controller_read(&self) -> &[u8] { | 73 | async fn controller_read_into(&self, buf: &mut [u8]) { |
| 74 | let evt_box = self.tl_read().await; | 74 | let evt_box = self.tl_read().await; |
| 75 | let evt_serial = evt_box.serial(); | ||
| 75 | 76 | ||
| 76 | evt_box.serial() | 77 | buf[..evt_serial.len()].copy_from_slice(evt_serial); |
| 77 | } | 78 | } |
| 78 | } | 79 | } |
diff --git a/embassy-stm32-wpan/src/evt.rs b/embassy-stm32-wpan/src/evt.rs index 7a4738b7a..25249a13a 100644 --- a/embassy-stm32-wpan/src/evt.rs +++ b/embassy-stm32-wpan/src/evt.rs | |||
| @@ -106,14 +106,6 @@ impl EvtBox { | |||
| 106 | Self { ptr } | 106 | Self { ptr } |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | pub fn evt<'a>(&self) -> &'a [u8] { | ||
| 110 | unsafe { | ||
| 111 | let evt_packet = &(*self.ptr); | ||
| 112 | |||
| 113 | core::slice::from_raw_parts(evt_packet as *const _ as *const u8, core::mem::size_of::<EvtPacket>()) | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | /// Returns information about the event | 109 | /// Returns information about the event |
| 118 | pub fn stub(&self) -> EvtStub { | 110 | pub fn stub(&self) -> EvtStub { |
| 119 | unsafe { | 111 | unsafe { |
| @@ -137,7 +129,7 @@ impl EvtBox { | |||
| 137 | /// writes an underlying [`EvtPacket`] into the provided buffer. | 129 | /// writes an underlying [`EvtPacket`] into the provided buffer. |
| 138 | /// Returns the number of bytes that were written. | 130 | /// Returns the number of bytes that were written. |
| 139 | /// Returns an error if event kind is unknown or if provided buffer size is not enough. | 131 | /// Returns an error if event kind is unknown or if provided buffer size is not enough. |
| 140 | pub fn serial<'a>(&self) -> &'a [u8] { | 132 | pub fn serial<'a>(&'a self) -> &'a [u8] { |
| 141 | unsafe { | 133 | unsafe { |
| 142 | let evt_serial: *const EvtSerial = &(*self.ptr).evt_serial; | 134 | let evt_serial: *const EvtSerial = &(*self.ptr).evt_serial; |
| 143 | let evt_serial_buf: *const u8 = evt_serial.cast(); | 135 | let evt_serial_buf: *const u8 = evt_serial.cast(); |
