Skip to content

Commit 0a3a9da

Browse files
andrewdavidmackenzielukipuki
authored andcommitted
Additional protection from panics on invalid input buffer lengths.
1 parent 9543620 commit 0a3a9da

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/connections/ble_handler.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,13 @@ impl BleHandler {
277277
pub async fn write_to_radio(&self, buffer: &[u8]) -> Result<(), Error> {
278278
self.radio
279279
// TODO: remove the skipping of the first 4 bytes
280-
.write(&self.toradio_char, &buffer[4..], WriteType::WithResponse)
280+
.write(
281+
&self.toradio_char,
282+
buffer.get(4..).ok_or(Error::InvalidaDataSize {
283+
data_length: buffer.len(),
284+
})?,
285+
WriteType::WithResponse,
286+
)
281287
.await
282288
.map_err(|e: btleplug::Error| {
283289
Error::InternalStreamError(InternalStreamError::StreamWriteError {

0 commit comments

Comments
 (0)