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:
Jiahao Li
2018-08-24 17:35:32 +00:00
committed by Akim Demaille
parent 55947367c6
commit c1cf82f9c8

View File

@@ -122,7 +122,7 @@ m4_define([b4_variant_define],
YYASSERT (!yytypeid_);
YYASSERT (sizeof (T) <= S);
yytypeid_ = & typeid (T);])[
return *new (yyas_<T> ()) T;
return *new (yyas_<T> ()) T ();
}
/// Instantiate a \a T in here from \a t.