Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f78b56cf authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "topshim: don't pass NULL to slice::from_raw_parts" into main am: 95173f08

parents 304cb88e 95173f08
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ use std::hash::{Hash, Hasher};
use std::mem;
use std::os::fd::RawFd;
use std::os::raw::c_char;
use std::ptr::NonNull;
use std::sync::{Arc, Mutex};
use std::vec::Vec;
use topshim_macros::{cb_variant, gen_cxx_extern_trivial};
@@ -788,9 +789,12 @@ impl BluetoothProperty {
// TODO(abps) - Check that sizes are correct when given a BtProperty
impl From<bindings::bt_property_t> for BluetoothProperty {
    fn from(prop: bindings::bt_property_t) -> Self {
        let slice: &[u8] =
            unsafe { std::slice::from_raw_parts(prop.val as *mut u8, prop.len as usize) };
        // Property values may be null, which isn't valid to pass for `slice::from_raw_parts`.
        // Choose a dangling pointer in that case.
        let prop_val_ptr =
            NonNull::new(prop.val as *mut u8).unwrap_or(NonNull::dangling()).as_ptr();
        let len = prop.len as usize;
        let slice: &[u8] = unsafe { std::slice::from_raw_parts(prop_val_ptr, len) };

        match BtPropertyType::from(prop.type_) {
            BtPropertyType::BdName => BluetoothProperty::BdName(ascii_to_string(slice, len)),