Adverserial use of `make_bitflags!` macro can cause undefined behavior
Moderate severity
GitHub Reviewed
Published
Apr 24, 2023
to the GitHub Advisory Database
•
Updated Apr 24, 2023
Description
Published to the GitHub Advisory Database
Apr 24, 2023
Reviewed
Apr 24, 2023
Last updated
Apr 24, 2023
The macro relied on an expression of the form
Enum::Variant
always being avariant 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 causeiterating over it to trigger undefined behavior. As the debug formatter
internally iterates over the value, it is also affected.
References