Skip to content

Commit

Permalink
Fix unsoundness in PdInfo::as_struct()
Browse files Browse the repository at this point in the history
  • Loading branch information
Sympatron committed Sep 28, 2024
1 parent 246a910 commit bcfb301
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions libosdp/src/pdinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,21 @@ impl PdInfoBuilder {
impl PdInfo {
/// Get a C-repr struct for PdInfo that LibOSDP can operate on.
pub fn as_struct(&mut self) -> libosdp_sys::osdp_pd_info_t {
let scbk;
if let Some(key) = self.scbk.as_mut() {
scbk = key.as_mut_ptr();
let scbk = if let Some(key) = self.scbk {
Box::into_raw(Box::new(key)) as *mut _
} else {
scbk = std::ptr::null_mut::<u8>();
}
std::ptr::null_mut::<u8>()
};
let mut cap = self.cap.clone();
let cap_ptr = cap.as_mut_ptr();
core::mem::forget(cap);
libosdp_sys::osdp_pd_info_t {
name: self.name.as_ptr(),
name: self.name.clone().into_raw(),
baud_rate: self.baud_rate,
address: self.address,
flags: self.flags.bits() as i32,
id: self.id.into(),
cap: self.cap.as_ptr(),
cap: cap_ptr,
channel: self.channel.take().unwrap().into(),
scbk,
}
Expand Down

0 comments on commit bcfb301

Please sign in to comment.