Security mailing lists by PureSourceCode

GHSA-qvc4-78gw-pv8p

MEDIUM

Adverserial use of `make_bitflags!` macro can cause undefined behavior

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
}
Published
17 Apr 2023
Last modified
8 Nov 2023
Also known as
RUSTSEC-2023-0035
Sources
OSVJSONOSV RUSTSEC-2023-0035JSON

Affected

SourceVendor / ecosystemProduct / packageAffected versionsFixed in
OSV crates.io enumflags2 >= 0.7.0, < 0.7.7 0.7.7

References

History

  • 25 Nov 2026 20:14 UTC · OSV: first stored (published 17 Apr 2023)
  • 25 Nov 2026 20:14 UTC · OSV: first stored (published 24 Apr 2023)
An unhandled error has occurred. Reload ×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.