diff options
author | Ted Pudlik <tpudlik@google.com> | 2021-11-05 17:14:49 +0000 |
---|---|---|
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2021-11-05 19:26:19 +0000 |
commit | 0211fdf8f27cd87c2245039a8c7eb3c1535d84b2 (patch) | |
tree | be25d290798a4cb207dd5a47c422930f3e0ba7c7 /pw_trace | |
parent | dd25904f4e13949588d18241e5225fbb6a6964d3 (diff) | |
download | pigweed-0211fdf8f27cd87c2245039a8c7eb3c1535d84b2.tar.gz |
pw_trace: Fix UB in fake_backend.h
Using memcmp to compare nullptr's is undefined behavior, so special
handling is required for the case when one of the pointers is null.
Tested by running,
ninja -C out host_clang_ubsan/obj/pw_trace/test/trace_facade_test
out/host_clang_ubsan/obj/pw_trace/test/trace_facade_test
Bug: 541
Change-Id: Id680516fe6066d827d64001bb772cb5ad4e73117
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/67343
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Commit-Queue: Ted Pudlik <tpudlik@google.com>
Diffstat (limited to 'pw_trace')
-rw-r--r-- | pw_trace/pw_trace_test/fake_backend.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/pw_trace/pw_trace_test/fake_backend.h b/pw_trace/pw_trace_test/fake_backend.h index c824e9ad9..f9dd3fcd1 100644 --- a/pw_trace/pw_trace_test/fake_backend.h +++ b/pw_trace/pw_trace_test/fake_backend.h @@ -95,7 +95,8 @@ class Event { has_data_ == rhs.has_data_ && // data_format_string_ == rhs.data_format_string_ && // data_size_ == rhs.data_size_ && // - (memcmp(data_, rhs.data_, data_size_) == 0); + (data_size_ == 0 || // + (memcmp(data_, rhs.data_, data_size_) == 0)); } bool IsEqualIgnoreLabel(const Event& rhs) const { @@ -105,7 +106,8 @@ class Event { has_data_ == rhs.has_data_ && // data_format_string_ == rhs.data_format_string_ && // data_size_ == rhs.data_size_ && // - (memcmp(data_, rhs.data_, data_size_) == 0); + (data_size_ == 0 || // + (memcmp(data_, rhs.data_, data_size_) == 0)); } private: @@ -140,4 +142,4 @@ class LastEvent { LastEvent::Instance().Set( \ Event(event_type, flags, label, group, trace_id, type, data, size)); -} // namespace trace_fake_backend
\ No newline at end of file +} // namespace trace_fake_backend |