{"id":"GHSA-wrw7-89jp-8q8g","aliases":["GHSA-wrw7-89jp-8q8g","RUSTSEC-2024-0429"],"related":[],"kind":"vulnerability","state":"published","title":"Unsoundness in `Iterator` and `DoubleEndedIterator` impls for `glib::VariantStrIter`","summary":"The `VariantStrIter::impl_get` function (called internally by implementations of the `Iterator` and `DoubleEndedIterator` traits for this type) was unsound, resulting in undefined behaviour.\n\nAn immutable reference `&p` to a `*mut libc::c_char` pointer initialized to `NULL` was passed as an argument to a C function that that mutates the pointer behind `&p` in-place (i.e. as an out-argument), which was unsound. After changes in recent versions of the Rust compiler, these unsound writes through `&p` now seem to be completely disregarded when building the `glib` crate with optimizations.\n\nThis subsequently caused all calls of `VariantStrIter::impl_get` to violate the safety requirements of the `std::ffi::CStr::from_ptr` function - which requires its argument to be a valid pointer to a C-style string - resulting in crashes due to `NULL` pointer dereferences.\n\nThis was fixed by passing the out-argument pointer explitly as `&mut p` instead of `&p`.\n\nThis issue has been present since this code was initially added in `glib` v0.15.0. The mismatch in mutability was likely missed (and not raised as an error by the compiler) because the C function wrapped by `VariantStrIter::impl_get` is variadic (`glib_sys::g_variant_get_child`), and the pointer in question is one of the variadic arguments.","summaryFormat":"markdown","summarySource":"ghsa","descriptions":[{"lang":"en","text":"The `VariantStrIter::impl_get` function (called internally by implementations of the `Iterator` and `DoubleEndedIterator` traits for this type) was unsound, resulting in undefined behaviour.\n\nAn immutable reference `&p` to a `*mut libc::c_char` pointer initialized to `NULL` was passed as an argument to a C function that that mutates the pointer behind `&p` in-place (i.e. as an out-argument), which was unsound. After changes in recent versions of the Rust compiler, these unsound writes through `&p` now seem to be completely disregarded when building the `glib` crate with optimizations.\n\nThis subsequently caused all calls of `VariantStrIter::impl_get` to violate the safety requirements of the `std::ffi::CStr::from_ptr` function - which requires its argument to be a valid pointer to a C-style string - resulting in crashes due to `NULL` pointer dereferences.\n\nThis was fixed by passing the out-argument pointer explitly as `&mut p` instead of `&p`.\n\nThis issue has been present since this code was initially added in `glib` v0.15.0. The mismatch in mutability was likely missed (and not raised as an error by the compiler) because the C function wrapped by `VariantStrIter::impl_get` is variadic (`glib_sys::g_variant_get_child`), and the pointer in question is one of the variadic arguments.","format":"markdown","source":"ghsa"}],"published":"2024-03-30T12:00:00.000Z","modified":"2025-10-28T06:29:26.473Z","severity":{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N","rating":"MEDIUM"},"severities":[{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N","rating":"MEDIUM"}],"cwes":[],"affected":[{"ranges":[{"type":"semver","introduced":"0.15.0","status":"affected","fixed":"0.20.0"}],"ecosystem":"crates.io","package":"glib","purl":"pkg:cargo/glib","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0.15.0","status":"affected","fixed":"0.20.0"}],"ecosystem":"crates.io","package":"glib","purl":"pkg:cargo/glib","source":"rustsec"}],"references":[{"url":"https://github.com/gtk-rs/gtk-rs-core/pull/1343","tags":["web"],"sources":["ghsa","rustsec"]},{"url":"https://github.com/gtk-rs/gtk-rs-core","tags":["package"],"sources":["ghsa"]},{"url":"https://rustsec.org/advisories/RUSTSEC-2024-0429.html","tags":["advisory","web"],"sources":["ghsa","rustsec"]},{"url":"https://crates.io/crates/glib","tags":["package"],"sources":["rustsec"]}],"credits":[],"sources":[{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-wrw7-89jp-8q8g","url":"https://github.com/advisories/GHSA-wrw7-89jp-8q8g","licence":"CC-BY-4.0","modified":"2025-10-28T06:29:26.473Z"},{"source":"rustsec","name":"RustSec Advisory Database","id":"RUSTSEC-2024-0429","url":"https://rustsec.org/advisories/RUSTSEC-2024-0429.html","licence":"CC0-1.0","modified":"2025-10-28T06:29:26.473Z"}],"updatedAt":"2026-11-25T22:56:43.232Z"}