{"id":"GHSA-wrw7-89jp-8q8g","aliases":["RUSTSEC-2024-0429"],"status":"published","title":"Unsoundness in `Iterator` and `DoubleEndedIterator` impls for `glib::VariantStrIter`","description":"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 `\u0026p` 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 `\u0026p` in-place (i.e. as an out-argument), which was unsound. After changes in recent versions of the Rust compiler, these unsound writes through `\u0026p` 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 `\u0026mut p` instead of `\u0026p`.\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.","severity":{"version":"4.0","score":6.9,"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","level":"medium","from":"ghsa"},"facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":true},"published":"2024-03-30T12:00:00Z","modified":"2025-10-28T06:29:26Z","fixes":[{"ecosystem":"crates.io","package":"glib","fixed_in":["0.20.0"],"sources":["ghsa","osv"]}],"affected":[{"source":"ghsa","ecosystem":"crates.io","package":"glib","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0.15.0"},{"fixed":"0.20.0"}]}]},{"source":"osv","ecosystem":"crates.io","package":"glib","ranges":[{"type":"SEMVER","events":[{"introduced":"0.15.0"},{"fixed":"0.20.0"}]}]},{"source":"osv","ecosystem":"crates.io","package":"glib","ranges":[{"type":"SEMVER","events":[{"introduced":"0.15.0"},{"fixed":"0.20.0"}]}]}],"references":[{"url":"https://github.com/gtk-rs/gtk-rs-core/pull/1343","tags":["web"]},{"url":"https://rustsec.org/advisories/RUSTSEC-2024-0429.html","tags":["web","advisory"]},{"url":"https://github.com/advisories/GHSA-wrw7-89jp-8q8g"},{"url":"https://github.com/gtk-rs/gtk-rs-core","tags":["package"]},{"url":"https://crates.io/crates/glib","tags":["package"]}],"sources":{"ghsa":[{"id":"GHSA-wrw7-89jp-8q8g","title":"Unsoundness in `Iterator` and `DoubleEndedIterator` impls for `glib::VariantStrIter`","description":"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 `\u0026p` 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 `\u0026p` in-place (i.e. as an out-argument), which was unsound. After changes in recent versions of the Rust compiler, these unsound writes through `\u0026p` 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 `\u0026mut p` instead of `\u0026p`.\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.\n\n","status":"published","published":"2024-12-23T20:19:24Z","modified":"2024-12-23T20:19:26Z","cvss":[{"version":"4.0","score":6.9,"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","level":"medium"}],"updated_at":"2026-11-02T14:38:26.167657Z"}],"osv":[{"id":"GHSA-wrw7-89jp-8q8g","title":"Unsoundness in `Iterator` and `DoubleEndedIterator` impls for `glib::VariantStrIter`","description":"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 `\u0026p` 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 `\u0026p` in-place (i.e. as an out-argument), which was unsound. After changes in recent versions of the Rust compiler, these unsound writes through `\u0026p` 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 `\u0026mut p` instead of `\u0026p`.\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.\n\n","status":"published","published":"2024-12-23T20:19:24Z","modified":"2025-10-28T06:29:26.473225Z","cvss":[{"version":"4.0","score":6.9,"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","level":"medium"}],"updated_at":"2026-11-02T15:46:59.131095Z"},{"id":"RUSTSEC-2024-0429","title":"Unsoundness in `Iterator` and `DoubleEndedIterator` impls for `glib::VariantStrIter`","description":"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 `\u0026p` 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 `\u0026p` in-place (i.e. as an out-argument), which was unsound. After changes in recent versions of the Rust compiler, these unsound writes through `\u0026p` 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 `\u0026mut p` instead of `\u0026p`.\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.","status":"published","published":"2024-03-30T12:00:00Z","modified":"2025-10-28T06:29:26.473225Z","updated_at":"2026-11-02T15:53:39.971022Z"}]}}
