"{0} initializer in C or C++ for unions no longer guarantees clearing of the whole union (except for static storage duration initialization)"
WHAT?!?!
This language.. I swear...
"{0} initializer in C or C++ for unions no longer guarantees clearing of the whole union (except for static storage duration initialization)"
WHAT?!?!
This language.. I swear...
@federicomena I'd be curious if there have been any MRs/PRs/patch submissions recently, where somebody just "reordered" unions fields in sec relevant software where it just happens the first member is now the smallest one leading to this situation 🙃
@karolherbst to be fair, I haven't checked if "let rust_enum = MyEnum::Something(blah)" zeros out the rest of the space in the enum. I guess the considerations there are different because the language won't let you access variants that are not valid, while in C "memset everything to 0" is pretty much a requirement to prevent fuckups.
@federicomena Well.. reads of C style unions in rust is unsafe at least.
@karolherbst I've actually never used C unions in Rust yet!
@federicomena they are a bit funky, but they can only have trivial drop. And writing to them is safe, but reading is unsafe for obvious reasons.
So you can just initialize a single union field and that field is valid, and anything else is undefined until you write to it. But because it's rust, you have to be explicit about which union field to initialize.
@karolherbst info disclosure CVE in 3... 2... 1...