Fix MSAN test

This commit is contained in:
BoloniniD 2022-09-08 22:25:46 +03:00
parent c08b41b611
commit ff82784b91
4 changed files with 7 additions and 1 deletions

View File

@ -53,6 +53,7 @@ dependencies = [
"blake3 1.2.0",
"cbindgen",
"cc",
"libc",
]
[[package]]

View File

@ -8,6 +8,7 @@ build = "build.rs"
[dependencies]
blake3 = "1.2.*"
libc = "0.2.*"
[lib]
crate-type = ["staticlib"]

View File

@ -1,6 +1,8 @@
use blake3::{Hasher, OUT_LEN};
use std::ffi::{CStr, CString};
use std::os::raw::c_char;
use libc;
use std::mem;
#[no_mangle]
pub unsafe extern "C" fn blake3_apply_shim(
@ -25,12 +27,13 @@ pub unsafe extern "C" fn blake3_apply_shim(
pub unsafe extern "C" fn blake3_apply_shim_msan_compat(
mut begin: *const c_char,
size: u32,
out_char_data: *mut u8,
mut out_char_data: *mut u8,
) -> *mut c_char {
if begin.is_null() {
let err_str = CString::new("input was a null pointer").unwrap();
return err_str.into_raw();
}
libc::memset(out_char_data as *mut libc::c_void, 0, mem::size_of::<u8>());
let mut hasher = Hasher::new();
let mut vec = Vec::<u8>::new();
for _ in 0..size {

View File

@ -603,6 +603,7 @@ struct ImplBLAKE3
{
#if defined(MEMORY_SANITIZER)
auto err_msg = blake3_apply_shim_msan_compat(begin, size, out_char_data);
__msan_unpoison(out_char_data, length);
#else
auto err_msg = blake3_apply_shim(begin, size, out_char_data);
#endif