Skip to content

Commit aef36e0

Browse files
authored
Merge pull request #2266 from alex/mem-bio-invariant
Fixed invariant violation in `MemBio::get_buf` with empty results
2 parents 32f150b + 142deef commit aef36e0

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

openssl/src/bio.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ impl MemBio {
6363
unsafe {
6464
let mut ptr = ptr::null_mut();
6565
let len = ffi::BIO_get_mem_data(self.0, &mut ptr);
66-
slice::from_raw_parts(ptr as *const _ as *const _, len as usize)
66+
if len == 0 {
67+
&[]
68+
} else {
69+
slice::from_raw_parts(ptr as *const _ as *const _, len as usize)
70+
}
6771
}
6872
}
6973

@@ -83,3 +87,14 @@ cfg_if! {
8387
}
8488
}
8589
}
90+
91+
#[cfg(test)]
92+
mod tests {
93+
use super::MemBio;
94+
95+
#[test]
96+
fn test_mem_bio_get_buf_empty() {
97+
let b = MemBio::new().unwrap();
98+
assert_eq!(b.get_buf(), &[]);
99+
}
100+
}

0 commit comments

Comments
 (0)