Skip to content

Commit

Permalink
protozero: Fix use-of-uninitialized-value in MessageHandleBase
Browse files Browse the repository at this point in the history
The diagnostic code in MessageHandleBase accesses an undefined value in
DCHECK builds:

==172==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x56024d8c3589 in protozero::MessageHandleBase::operator->() const ./../../third_party/perfetto/include/perfetto/protozero/message_handle.h:68:5
    #1 0x56025e928e5f in operator-> ./../../third_party/perfetto/include/perfetto/protozero/message_handle.h:116:47
    #2 0x56025e928e5f in tracing::(anonymous namespace)::ProtoWriter::AddDictEntry(char const*) ./../../services/tracing/public/cpp/perfetto/traced_value_proto_writer.cc:231:5
    #3 0x56025e921166 in tracing::(anonymous namespace)::ProtoWriter::SetInteger(char const*, int) ./../../services/tracing/public/cpp/perfetto/traced_value_proto_writer.cc:75:5
    #4 0x56025fcc90a6 in cc::benchmark_instrumentation::IssueDisplayRenderingStatsEvent() ./../../cc/benchmarks/benchmark_instrumentation.cc:24:16
    #5 0x56026026126c in viz::Display::DrawAndSwap() ./../../components/viz/service/display/display.cc:628:5
    #6 0x5602602c641e in viz::DisplayScheduler::DrawAndSwap() ./../../components/viz/service/display/display_scheduler.cc:215:38
    #7 0x5602602c4318 in viz::DisplayScheduler::AttemptDrawAndSwap() ./../../components/viz/service/display/display_scheduler.cc:488:14
    #8 0x5602602c2ec2 in viz::DisplayScheduler::OnBeginFrameDeadline() ./../../components/viz/service/display/display_scheduler.cc:504:19
    #9 0x56024b77fdb9 in base::OnceCallback<void ()>::Run() && ./../../base/callback.h:98:12
    #10 0x56025afac3d6 in Run ./../../base/callback.h:98:12
    #11 0x56025afac3d6 in base::TaskAnnotator::RunTask(char const*, base::PendingTask*) ./../../base/task/common/task_annotator.cc:142:33
    #12 0x56025b04d159 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::sequence_manager::LazyNow*, bool*) ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:365:23
    #13 0x56025b04c0f6 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoSomeWork() ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:219:7
    #14 0x56025ae37368 in base::MessagePumpDefault::Run(base::MessagePump::Delegate*) ./../../base/message_loop/message_pump_default.cc:39:55
    #15 0x56025b050925 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool, base::TimeDelta) ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:463:12
    #16 0x56025af07594 in base::RunLoop::Run() ./../../base/run_loop.cc:156:14
    #17 0x56025b1171f0 in base::Thread::Run(base::RunLoop*) ./../../base/threading/thread.cc:305:13
    #18 0x56025b118599 in base::Thread::ThreadMain() ./../../base/threading/thread.cc:376:3
    #19 0x56025b2c2e2c in base::(anonymous namespace)::ThreadFunc(void*) ./../../base/threading/platform_thread_posix.cc:81:13
    #20 0x7f00bb5d9183 in pthread_create@@GLIBC_2.2.5 ??:0:0
    #21 0x7f00b5e7e03c in getspnam_r ??:0:0

  Uninitialized value was stored to memory at
    #0 0x56024d8afaf7 in protozero::Message::Reset(protozero::ScatteredStreamWriter*) ./../../third_party/perfetto/src/protozero/message.cc:64:14
    #1 0x56025e92052b in ProtoWriter ./../../services/tracing/public/cpp/perfetto/traced_value_proto_writer.cc:54:12
    #2 0x56025e92052b in make_unique<tracing::(anonymous namespace)::ProtoWriter, unsigned long &> ./../../buildtools/third_party/libc++/trunk/include/memory:3043:32
    #3 0x56025e92052b in tracing::(anonymous namespace)::CreateNestedValueProtoWriter(unsigned long) ./../../services/tracing/public/cpp/perfetto/traced_value_proto_writer.cc:256:10
    #4 0x56025b1ed987 in CreateWriter ./../../base/trace_event/traced_value.cc:436:12
    #5 0x56025b1ed987 in base::trace_event::TracedValue::TracedValue(unsigned long, bool) ./../../base/trace_event/traced_value.cc:459:26
    #6 0x56025fcc906d in cc::benchmark_instrumentation::IssueDisplayRenderingStatsEvent() ./../../cc/benchmarks/benchmark_instrumentation.cc:23:11
    #7 0x56026026126c in viz::Display::DrawAndSwap() ./../../components/viz/service/display/display.cc:628:5
    #8 0x5602602c641e in viz::DisplayScheduler::DrawAndSwap() ./../../components/viz/service/display/display_scheduler.cc:215:38
    #9 0x5602602c4318 in viz::DisplayScheduler::AttemptDrawAndSwap() ./../../components/viz/service/display/display_scheduler.cc:488:14
    #10 0x5602602c2ec2 in viz::DisplayScheduler::OnBeginFrameDeadline() ./../../components/viz/service/display/display_scheduler.cc:504:19
    #11 0x56024b77fdb9 in base::OnceCallback<void ()>::Run() && ./../../base/callback.h:98:12
    #12 0x56025afac3d6 in Run ./../../base/callback.h:98:12
    #13 0x56025afac3d6 in base::TaskAnnotator::RunTask(char const*, base::PendingTask*) ./../../base/task/common/task_annotator.cc:142:33
    #14 0x56025b04d159 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::sequence_manager::LazyNow*, bool*) ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:365:23
    #15 0x56025b04c0f6 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoSomeWork() ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:219:7
    #16 0x56025ae37368 in base::MessagePumpDefault::Run(base::MessagePump::Delegate*) ./../../base/message_loop/message_pump_default.cc:39:55
    #17 0x56025b050925 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool, base::TimeDelta) ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:463:12
    #18 0x56025af07594 in base::RunLoop::Run() ./../../base/run_loop.cc:156:14
    #19 0x56025b1171f0 in base::Thread::Run(base::RunLoop*) ./../../base/threading/thread.cc:305:13
    #20 0x56025b118599 in base::Thread::ThreadMain() ./../../base/threading/thread.cc:376:3
    #21 0x56025b2c2e2c in base::(anonymous namespace)::ThreadFunc(void*) ./../../base/threading/platform_thread_posix.cc:81:13
    #22 0x7f00bb5d9183 in pthread_create@@GLIBC_2.2.5 ??:0:0

 Uninitialized value was created by a heap allocation
    #0 0x56024b74c9a9 in operator new(unsigned long) /b/swarming/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/msan/msan_new_delete.cpp:45:35
    #1 0x56025e9203f7 in make_unique<tracing::(anonymous namespace)::ProtoWriter, unsigned long &> ./../../buildtools/third_party/libc++/trunk/include/memory:3043:28
    #2 0x56025e9203f7 in tracing::(anonymous namespace)::CreateNestedValueProtoWriter(unsigned long) ./../../services/tracing/public/cpp/perfetto/traced_value_proto_writer.cc:256:10
    #3 0x56025b1ed987 in CreateWriter ./../../base/trace_event/traced_value.cc:436:12
    #4 0x56025b1ed987 in base::trace_event::TracedValue::TracedValue(unsigned long, bool) ./../../base/trace_event/traced_value.cc:459:26
    #5 0x56025fcc906d in cc::benchmark_instrumentation::IssueDisplayRenderingStatsEvent() ./../../cc/benchmarks/benchmark_instrumentation.cc:23:11
    #6 0x56026026126c in viz::Display::DrawAndSwap() ./../../components/viz/service/display/display.cc:628:5
    #7 0x5602602c641e in viz::DisplayScheduler::DrawAndSwap() ./../../components/viz/service/display/display_scheduler.cc:215:38
    #8 0x5602602c4318 in viz::DisplayScheduler::AttemptDrawAndSwap() ./../../components/viz/service/display/display_scheduler.cc:488:14
    #9 0x5602602c2ec2 in viz::DisplayScheduler::OnBeginFrameDeadline() ./../../components/viz/service/display/display_scheduler.cc:504:19
    #10 0x56024b77fdb9 in base::OnceCallback<void ()>::Run() && ./../../base/callback.h:98:12
    #11 0x56025afac3d6 in Run ./../../base/callback.h:98:12
    #12 0x56025afac3d6 in base::TaskAnnotator::RunTask(char const*, base::PendingTask*) ./../../base/task/common/task_annotator.cc:142:33
    #13 0x56025b04d159 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::sequence_manager::LazyNow*, bool*) ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:365:23
    #14 0x56025b04c0f6 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoSomeWork() ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:219:7
    #15 0x56025ae37368 in base::MessagePumpDefault::Run(base::MessagePump::Delegate*) ./../../base/message_loop/message_pump_default.cc:39:55
    #16 0x56025b050925 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool, base::TimeDelta) ./../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:463:12
    #17 0x56025af07594 in base::RunLoop::Run() ./../../base/run_loop.cc:156:14
    #18 0x56025b1171f0 in base::Thread::Run(base::RunLoop*) ./../../base/threading/thread.cc:305:13
    #19 0x56025b118599 in base::Thread::ThreadMain() ./../../base/threading/thread.cc:376:3
    #20 0x56025b2c2e2c in base::(anonymous namespace)::ThreadFunc(void*) ./../../base/threading/platform_thread_posix.cc:81:13
    #21 0x7f00bb5d9183 in pthread_create@@GLIBC_2.2.5 ??:0:0

Bug: chromium:1030032
Test: cast_shell_browsertests built with is_msan=true

Change-Id: I0f7fe0d0ec085f7a87028639e9a1ca70617fff3e
  • Loading branch information
mspang committed Dec 2, 2019
1 parent a5287b0 commit e09dcfb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/protozero/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "perfetto/protozero/message.h"

#include <atomic>
#include <type_traits>

#include "perfetto/base/logging.h"
Expand All @@ -29,6 +30,14 @@

namespace protozero {

namespace {

#if PERFETTO_DCHECK_IS_ON()
std::atomic<uint32_t> g_generation;
#endif

} // namespace

// static
constexpr uint32_t Message::kMaxNestingDepth;

Expand Down Expand Up @@ -61,7 +70,7 @@ void Message::Reset(ScatteredStreamWriter* stream_writer) {
finalized_ = false;
#if PERFETTO_DCHECK_IS_ON()
handle_ = nullptr;
generation_++;
generation_ = g_generation.fetch_add(1, std::memory_order_relaxed);
#endif
}

Expand Down

0 comments on commit e09dcfb

Please sign in to comment.