Email me

Rust advisories / glib

Unsound MediumRUSTSEC-2024-0429 · glib

RUSTSEC-2024-0429: Unsoundness in `Iterator` and `DoubleEndedIterator` impls for `glib::VariantStrIter`

Short answerglib has an API that can cause undefined behaviour from safe code: Unsoundness in `Iterator` and `DoubleEndedIterator` impls for `glib::VariantStrIter`. Fixed in 0.20.0.

Crateglib
TypeUnsound
Affected versionsFrom 0.15.0 before 0.20.0.
Fixed in0.20.0
SeverityMedium (GitHub rating)
Published2024-03-30
Last changed2025-10-28
Also known asGHSA-wrw7-89jp-8q8g
Affected functionsglib::VariantStrIter::last, glib::VariantStrIter::next, glib::VariantStrIter::next_back, glib::VariantStrIter::nth, glib::VariantStrIter::nth_back

What to do

  1. See which version you have: cargo tree -i glib (it also shows which of your dependencies pulls it in).
  2. Update within your version requirement: cargo update -p glib. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for example glib = "0.20.0") or update the dependency that pulls it in.
  3. Check again with cargo audit, or paste your Cargo.lock into our Cargo.toml checker.

Details from the advisory

The VariantStrIter::impl_get function (called internally by implementations of the Iterator and DoubleEndedIterator traits for this type) was unsound, resulting in undefined behaviour.

An 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.

This 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.

This was fixed by passing the out-argument pointer explitly as &mut p instead of &p.

This 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.

References

From the RustSec Advisory Database (CC0-1.0) via the OSV export, downloaded Oct 24, 2026. Severity score computed from the published CVSS vector.

Up next

Are you affected?Check your whole dependency treePaste Cargo.lock: every advisory, for your exact versions.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ