Skip to content

Commit

Permalink
Merge pull request #2266 from alex/mem-bio-invariant
Browse files Browse the repository at this point in the history
Fixed invariant violation in `MemBio::get_buf` with empty results
  • Loading branch information
alex committed Jul 21, 2024
2 parents 32f150b + 142deef commit aef36e0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion openssl/src/bio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ impl MemBio {
unsafe {
let mut ptr = ptr::null_mut();
let len = ffi::BIO_get_mem_data(self.0, &mut ptr);
slice::from_raw_parts(ptr as *const _ as *const _, len as usize)
if len == 0 {
&[]
} else {
slice::from_raw_parts(ptr as *const _ as *const _, len as usize)
}
}
}

Expand All @@ -83,3 +87,14 @@ cfg_if! {
}
}
}

#[cfg(test)]
mod tests {
use super::MemBio;

#[test]
fn test_mem_bio_get_buf_empty() {
let b = MemBio::new().unwrap();
assert_eq!(b.get_buf(), &[]);
}
}

0 comments on commit aef36e0

Please sign in to comment.