mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-15 15:23:02 +00:00
variant: fix uninitialized memory access in variant<>
Currently, in bison's C++ parser template (`lalr.cc`), the `variant<>` struct's `build()` method uses placement-new in the form `new (...) T` to initialize a variant type. However, for POD variant types, this will leave the memory space uninitialized. If we subsequently tries to `::move` into a variant object in such state, the call can trigger clang's undefined behavior sanitizer due to accessing the uninitialized memory. https://lists.gnu.org/archive/html/bison-patches/2018-08/msg00098.html * data/variant.hh (build): Always initialize the stored value. Signed-off-by: Akim Demaille <akim@lrde.epita.fr>
This commit is contained in:
@@ -122,7 +122,7 @@ m4_define([b4_variant_define],
|
|||||||
YYASSERT (!yytypeid_);
|
YYASSERT (!yytypeid_);
|
||||||
YYASSERT (sizeof (T) <= S);
|
YYASSERT (sizeof (T) <= S);
|
||||||
yytypeid_ = & typeid (T);])[
|
yytypeid_ = & typeid (T);])[
|
||||||
return *new (yyas_<T> ()) T;
|
return *new (yyas_<T> ()) T ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiate a \a T in here from \a t.
|
/// Instantiate a \a T in here from \a t.
|
||||||
|
|||||||
Reference in New Issue
Block a user