# GHSA-qvc4-78gw-pv8p: Adverserial use of `make_bitflags!` macro can cause undefined behavior

- Severity: Medium (rating, scored by GitHub)
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Published: 2023-04-17T12:00:00.000Z
- Modified: 2023-11-08T04:22:24.773Z
- Also known as: RUSTSEC-2023-0035

## Description

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.

```rust
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
}
```

(As written by GitHub Advisory Database.)

## Affected

- enumflags2 (crates.io): from 0.7.0 before 0.7.7

## References

- <https://github.com/meithecatte/enumflags2> (package)
- <https://github.com/meithecatte/enumflags2/releases/tag/v0.7.7> (web)
- <https://rustsec.org/advisories/RUSTSEC-2023-0035.html> (advisory, web)
- <https://crates.io/crates/enumflags2> (package)

## Sources

- GitHub Advisory Database: [GHSA-qvc4-78gw-pv8p](https://github.com/advisories/GHSA-qvc4-78gw-pv8p), CC-BY-4.0, modified 2023-11-08
- RustSec Advisory Database: [RUSTSEC-2023-0035](https://rustsec.org/advisories/RUSTSEC-2023-0035.html), CC0-1.0, modified 2023-11-08

---

Page: https://cve.day/GHSA-qvc4-78gw-pv8p · Whole record: https://cve.day/GHSA-qvc4-78gw-pv8p.json · Rebuilt by cve.day 2026-11-25T22:56:43.147Z
