Merge pull request #1396 from micahsnyder/CLAM-2710-ldb-load-assert

Fix a possible crash when loading a malformed logical signature
pull/1366/head
Micah Snyder 4 months ago committed by GitHub
commit de3be9e891
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      libclamav_rust/src/evidence.rs
  2. 28
      libclamav_rust/src/ffi_util.rs
  3. 2
      libclamav_rust/src/fuzzy_hash.rs

@ -209,7 +209,7 @@ pub unsafe extern "C" fn _evidence_add_indicator(
indicator_type: IndicatorType,
err: *mut *mut FFIError,
) -> bool {
let name_str = validate_str_param!(name);
let name_str = validate_str_param!(name, err = err);
let mut evidence = ManuallyDrop::new(Box::from_raw(evidence as *mut Evidence));

@ -288,6 +288,13 @@ mod tests {
/// let blah = validate_str_param!(blah);
/// # }
/// ```
/// ```edition2018
/// use util::validate_str_param;
///
/// # pub extern "C" fn _my_c_interface(blah: *const c_char) -> sys::cl_error_t {
/// let blah = validate_str_param!(blah, err = err);
/// # }
/// ```
#[macro_export]
macro_rules! validate_str_param {
($ptr:ident) => {
@ -305,4 +312,25 @@ macro_rules! validate_str_param {
}
}
};
($ptr:ident, err=$err:ident) => {
if $err.is_null() {
warn!("{} is NULL", stringify!($err));
return false;
} else if $ptr.is_null() {
warn!("{} is NULL", stringify!($ptr));
return false;
} else {
#[allow(unused_unsafe)]
match unsafe { CStr::from_ptr($ptr) }.to_str() {
Err(e) => {
warn!("{} is not valid unicode: {}", stringify!($ptr), e);
*$err = Box::into_raw(Box::new(e.into()));
return false;
}
Ok(s) => s,
}
}
};
}

@ -181,7 +181,7 @@ pub unsafe extern "C" fn _fuzzy_hash_load_subsignature(
subsig_id: u32,
err: *mut *mut FFIError,
) -> bool {
let hexsig = validate_str_param!(hexsig);
let hexsig = validate_str_param!(hexsig, err=err);
let mut hashmap = ManuallyDrop::new(Box::from_raw(fuzzy_hashmap as *mut FuzzyHashMap));

Loading…
Cancel
Save