Advisory

RUSTSEC-2023-0035

Also known as: GHSA-qvc4-78gw-pv8p

Summary

Adverserial use of make_bitflags! macro can cause undefined behavior

Details

The macro relied on an expression of the form Enum::Variant always being a
variant of the enum. However, it may also be an associated integer constant, in
which case there's no guarantee that the value of said constant consists only of
bits valid for this bitflag type.

Thus, code like this could create an invalid BitFlags<Test>, which would cause
iterating over it to trigger undefined behavior. As the debug formatter
internally iterates over the value, it is also affected.

use enumflags2::{bitflags, make_bitflags};

#[bitflags]
#[repr(u8)]
#[derive(Copy, Clone, Debug)]
enum Test {
    A = 1,
    B = 2,
}

impl Test {
    const C: u8 = 69;
}

fn main() {
    let x = make_bitflags!(Test::{C});
    // printing or iterating over x is UB
}

Severity

Not rated by the source.

Dates

Published
2023-04-17 12:00 UTC
Modified
2023-11-08 04:22 UTC

Affected packages and fixes

enumflags2

crates.io · All systems

Affected

  • introduced 0.7.0, fixed 0.7.7 (semver)

Fixed versions

0.7.7

Fix

  • Fixed version 0.7.7
    cargo update -p enumflags2 --precise 0.7.7

Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.

Check your own computer: guard packages check

View this record on OSV.dev

Source

Source: RustSec Advisory Database · CC0-1.0

Sources & licences