Advisory

RUSTSEC-2020-0161

Also known as: GHSA-83gg-pwxf-jr89

Summary

array! macro is unsound in presence of traits that implement methods it calls internally

Details

Affected versions of this crate called some methods using auto-ref. The affected code looked like this.

let mut arr = $crate::__core::mem::MaybeUninit::uninit();
let mut vec = $crate::__ArrayVec::<T>::new(arr.as_mut_ptr() as *mut T);

In this case, the problem is that as_mut_ptr is a method of &mut MaybeUninit, not MaybeUninit. This made it possible for traits to hijack the method calls in order to cause unsoundness.

trait AsMutPtr<T> {
    fn as_mut_ptr(&self) -> *mut T;
}
impl<T> AsMutPtr<T> for std::mem::MaybeUninit<T> {
    fn as_mut_ptr(&self) -> *mut T {
        std::ptr::null_mut()
    }
}
array![0; 1];

The flaw was corrected by explicitly referencing variables in macro body in order to avoid auto-ref.

Severity

Not rated by the source.

Dates

Published
2020-05-07 12:00 UTC
Modified
2023-11-08 04:17 UTC

Affected packages and fixes

array-macro

crates.io · All systems

Affected

  • introduced 0.1.2, fixed 1.0.5 (semver)

Fixed versions

1.0.5

Fix

  • Fixed version 1.0.5
    cargo update -p array-macro --precise 1.0.5

Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.

Check your own computer: guard packages check

View this record on OSV.dev

Source

Source: RustSec Advisory Database · CC0-1.0

Sources & licences