Advisory Database
  • Advisories
  • Dependency Scanning
  1. cargo
  2. ›
  3. glib
  4. ›
  5. GHSA-wrw7-89jp-8q8g

GHSA-wrw7-89jp-8q8g: Unsoundness in `Iterator` and `DoubleEndedIterator` impls for `glib::VariantStrIter`

December 23, 2024

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

  • github.com/advisories/GHSA-wrw7-89jp-8q8g
  • github.com/gtk-rs/gtk-rs-core
  • github.com/gtk-rs/gtk-rs-core/pull/1343
  • rustsec.org/advisories/RUSTSEC-2024-0429.html

Code Behaviors & Features

Detect and mitigate GHSA-wrw7-89jp-8q8g with GitLab Dependency Scanning

Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →

Affected versions

All versions starting from 0.15.0 before 0.20.0

Fixed versions

  • 0.20.0

Solution

Upgrade to version 0.20.0 or above.

Source file

cargo/glib/GHSA-wrw7-89jp-8q8g.yml

Spotted a mistake? Edit the file on GitLab.

  • Site Repo
  • About GitLab
  • Terms
  • Privacy Statement
  • Contact

Page generated Wed, 14 May 2025 12:15:08 +0000.