Unverified Commit aef36e0f authored by Alex Gaynor's avatar Alex Gaynor Committed by GitHub
Browse files

Merge pull request #2266 from alex/mem-bio-invariant

Fixed invariant violation in `MemBio::get_buf` with empty results
parents 32f150b0 142deef7
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -63,9 +63,13 @@ impl MemBio {
        unsafe {
            let mut ptr = ptr::null_mut();
            let len = ffi::BIO_get_mem_data(self.0, &mut ptr);
            if len == 0 {
                &[]
            } else {
                slice::from_raw_parts(ptr as *const _ as *const _, len as usize)
            }
        }
    }

    #[cfg(not(boringssl))]
    pub unsafe fn from_ptr(bio: *mut ffi::BIO) -> MemBio {
@@ -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(), &[]);
    }
}