From 16880d4e3c06e835a6270016b2556bac62f6e47c Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Thu, 8 Apr 2021 07:10:16 -0700 Subject: [PATCH] Fix `Reg` for MSAN On x86 `long double` has 10 bytes of meaningful data, but `sizeof(long double)` is 16 - the remaining bytes are random garbage. PiperOrigin-RevId: 367423349 Change-Id: I769b3444ce4fa60f941ccd2115b0b09ccc809f13 --- sandboxed_api/BUILD.bazel | 1 + sandboxed_api/CMakeLists.txt | 1 + sandboxed_api/client.cc | 2 ++ sandboxed_api/var_reg.h | 7 ++++--- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sandboxed_api/BUILD.bazel b/sandboxed_api/BUILD.bazel index 63f4ef3..df65c79 100644 --- a/sandboxed_api/BUILD.bazel +++ b/sandboxed_api/BUILD.bazel @@ -157,6 +157,7 @@ cc_library( "//sandboxed_api/sandbox2:comms", "//sandboxed_api/util:status", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/base:dynamic_annotations", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", diff --git a/sandboxed_api/CMakeLists.txt b/sandboxed_api/CMakeLists.txt index a023d86..7c2adfc 100644 --- a/sandboxed_api/CMakeLists.txt +++ b/sandboxed_api/CMakeLists.txt @@ -150,6 +150,7 @@ add_library(sapi_vars ${SAPI_LIB_TYPE} add_library(sapi::vars ALIAS sapi_vars) target_link_libraries(sapi_vars PRIVATE absl::core_headers + absl::dynamic_annotations absl::status absl::statusor absl::str_format diff --git a/sandboxed_api/client.cc b/sandboxed_api/client.cc index ab8c5ec..81e9c2a 100644 --- a/sandboxed_api/client.cc +++ b/sandboxed_api/client.cc @@ -396,6 +396,8 @@ void ServeRequest(sandbox2::Comms* comms) { } if (ret.ret_type == v::Type::kFloat) { + // Make MSAN happy with long double. + ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(ret.float_val, sizeof(ret.float_val)); VLOG(1) << "Returned value: " << ret.float_val << ", Success: " << (ret.success ? "Yes" : "No"); } else { diff --git a/sandboxed_api/var_reg.h b/sandboxed_api/var_reg.h index bc46e6f..caab6ec 100644 --- a/sandboxed_api/var_reg.h +++ b/sandboxed_api/var_reg.h @@ -19,6 +19,7 @@ #include #include +#include "absl/base/dynamic_annotations.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "sandboxed_api/var_abstract.h" @@ -57,10 +58,10 @@ class Reg : public Callable { "Only register-sized types are allowed as template argument " "for class Reg."); - Reg() : Reg(static_cast(0)) {} - - explicit Reg(const T val) { + explicit Reg(const T val = {}) { val_ = val; + // Make MSAN happy with long double. + ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(val_, sizeof(val_)); SetLocal(&val_); }