Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1214)

Unified Diff: mojo/public/cpp/bindings/lib/message.cc

Issue 2844143002: Mojo C++ bindings: reject messages version 2 with null payload pointer. (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/js/tests/js_to_cpp_tests.js ('k') | mojo/public/cpp/bindings/lib/message_header_validator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/message.cc
diff --git a/mojo/public/cpp/bindings/lib/message.cc b/mojo/public/cpp/bindings/lib/message.cc
index e5f38081176f5843c59669fcd5ba64b001cc2383..50d6d6758014d65465d55e4a6d30760377ab5d0f 100644
--- a/mojo/public/cpp/bindings/lib/message.cc
+++ b/mojo/public/cpp/bindings/lib/message.cc
@@ -80,6 +80,7 @@ const uint8_t* Message::payload() const {
if (version() < 2)
return data() + header()->num_bytes;
+ DCHECK(!header_v2()->payload.is_null());
return static_cast<const uint8_t*>(header_v2()->payload.Get());
}
@@ -89,17 +90,14 @@ uint32_t Message::payload_num_bytes() const {
if (version() < 2) {
num_bytes = data_num_bytes() - header()->num_bytes;
} else {
- auto payload = reinterpret_cast<uintptr_t>(header_v2()->payload.Get());
- if (!payload) {
- num_bytes = 0;
- } else {
- auto payload_end =
- reinterpret_cast<uintptr_t>(header_v2()->payload_interface_ids.Get());
- if (!payload_end)
- payload_end = reinterpret_cast<uintptr_t>(data() + data_num_bytes());
- DCHECK_GE(payload_end, payload);
- num_bytes = payload_end - payload;
- }
+ auto payload_begin =
+ reinterpret_cast<uintptr_t>(header_v2()->payload.Get());
+ auto payload_end =
+ reinterpret_cast<uintptr_t>(header_v2()->payload_interface_ids.Get());
+ if (!payload_end)
+ payload_end = reinterpret_cast<uintptr_t>(data() + data_num_bytes());
+ DCHECK_GE(payload_end, payload_begin);
+ num_bytes = payload_end - payload_begin;
}
DCHECK_LE(num_bytes, std::numeric_limits<uint32_t>::max());
return static_cast<uint32_t>(num_bytes);
« no previous file with comments | « mojo/edk/js/tests/js_to_cpp_tests.js ('k') | mojo/public/cpp/bindings/lib/message_header_validator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698