{"id":"GHSA-83gg-pwxf-jr89","aliases":["RUSTSEC-2020-0161"],"url":"https://o3.security/vulnerability/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.\n\n```rust\nlet mut arr = $crate::__core::mem::MaybeUninit::uninit();\nlet mut vec = $crate::__ArrayVec::<T>::new(arr.as_mut_ptr() as *mut T);\n```\n\nIn 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.\n\n```rust\ntrait AsMutPtr<T> {\n    fn as_mut_ptr(&self) -> *mut T;\n}\nimpl<T> AsMutPtr<T> for std::mem::MaybeUninit<T> {\n    fn as_mut_ptr(&self) -> *mut T {\n        std::ptr::null_mut()\n    }\n}\narray![0; 1];\n```\n\nThe flaw was corrected by explicitly referencing variables in macro body in order to avoid auto-ref.\n","published":"2022-06-16T23:40:19Z","modified":"2023-11-08T04:17:08.031225Z","cvss":null,"epss":null,"cisaKev":null,"exploitsKnown":0,"affectedPackages":[{"ecosystem":"crates.io","name":"array-macro","fixedVersion":"1.0.5"}],"fix":{"url":"https://github.com/xfix/array-macro/commit/01940637dd8f3bfeeee3faf9639fa9ae52f19f4d","label":"xfix/array-macro@0194063"},"references":[{"type":"WEB","url":"https://github.com/xfix/array-macro/commit/01940637dd8f3bfeeee3faf9639fa9ae52f19f4d"},{"type":"WEB","url":"https://github.com/rustsec/advisory-db/blob/main/crates/array-macro/RUSTSEC-2020-0161.md"},{"type":"PACKAGE","url":"https://github.com/xfix/array-macro"},{"type":"WEB","url":"https://gitlab.com/KonradBorowski/array-macro/-/commit/01940637dd8f3bfeeee3faf9639fa9ae52f19f4d"},{"type":"WEB","url":"https://rustsec.org/advisories/RUSTSEC-2020-0161.html"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2023-11-08T04:17:08.031225Z"}}