Index: mojo/edk/system/message_in_transit.cc |
diff --git a/mojo/edk/system/message_in_transit.cc b/mojo/edk/system/message_in_transit.cc |
index 95a7d2312ed3ca6a01a24ebc61ec83a5c19216f4..0f2ff5e6e69a4de8e721b5db6ec39ca7c7267d18 100644 |
--- a/mojo/edk/system/message_in_transit.cc |
+++ b/mojo/edk/system/message_in_transit.cc |
@@ -8,7 +8,7 @@ |
#include "base/compiler_specific.h" |
#include "base/logging.h" |
-#include "mojo/edk/system/constants.h" |
+#include "mojo/edk/system/configuration.h" |
#include "mojo/edk/system/transport_data.h" |
namespace mojo { |
@@ -38,23 +38,13 @@ struct MessageInTransit::PrivateStructForCompileAsserts { |
// The size of |Header| must be a multiple of the alignment. |
static_assert(sizeof(Header) % kMessageAlignment == 0, |
"sizeof(MessageInTransit::Header) invalid"); |
- // Avoid dangerous situations, but making sure that the size of the "header" + |
- // the size of the data fits into a 31-bit number. |
- static_assert(static_cast<uint64_t>(sizeof(Header)) + kMaxMessageNumBytes <= |
- 0x7fffffffULL, |
- "kMaxMessageNumBytes too big"); |
- |
- // We assume (to avoid extra rounding code) that the maximum message (data) |
- // size is a multiple of the alignment. |
- static_assert(kMaxMessageNumBytes % kMessageAlignment == 0, |
- "kMessageAlignment not a multiple of alignment"); |
}; |
MessageInTransit::View::View(size_t message_size, const void* buffer) |
: buffer_(buffer) { |
size_t next_message_size = 0; |
- DCHECK(MessageInTransit::GetNextMessageSize( |
- buffer_, message_size, &next_message_size)); |
+ DCHECK(MessageInTransit::GetNextMessageSize(buffer_, message_size, |
+ &next_message_size)); |
DCHECK_EQ(message_size, next_message_size); |
// This should be equivalent. |
DCHECK_EQ(message_size, total_size()); |
@@ -62,18 +52,29 @@ MessageInTransit::View::View(size_t message_size, const void* buffer) |
bool MessageInTransit::View::IsValid(size_t serialized_platform_handle_size, |
const char** error_message) const { |
+ size_t max_message_num_bytes = GetConfiguration().max_message_num_bytes; |
+ // Avoid dangerous situations, but making sure that the size of the "header" + |
+ // the size of the data fits into a 31-bit number. |
+ DCHECK_LE(static_cast<uint64_t>(sizeof(Header)) + max_message_num_bytes, |
+ 0x7fffffffULL) |
+ << "GetConfiguration().max_message_num_bytes too big"; |
+ |
+ // We assume (to avoid extra rounding code) that the maximum message (data) |
+ // size is a multiple of the alignment. |
+ DCHECK_EQ(max_message_num_bytes % kMessageAlignment, 0U) |
+ << "GetConfiguration().max_message_num_bytes not a multiple of alignment"; |
+ |
// Note: This also implies a check on the |main_buffer_size()|, which is just |
// |RoundUpMessageAlignment(sizeof(Header) + num_bytes())|. |
- if (num_bytes() > kMaxMessageNumBytes) { |
+ if (num_bytes() > max_message_num_bytes) { |
*error_message = "Message data payload too large"; |
return false; |
} |
if (transport_data_buffer_size() > 0) { |
- const char* e = |
- TransportData::ValidateBuffer(serialized_platform_handle_size, |
- transport_data_buffer(), |
- transport_data_buffer_size()); |
+ const char* e = TransportData::ValidateBuffer( |
+ serialized_platform_handle_size, transport_data_buffer(), |
+ transport_data_buffer_size()); |
if (e) { |
*error_message = e; |
return false; |
@@ -93,8 +94,7 @@ MessageInTransit::MessageInTransit(Type type, |
ConstructorHelper(type, subtype, num_bytes); |
if (bytes) { |
memcpy(MessageInTransit::bytes(), bytes, num_bytes); |
- memset(static_cast<char*>(MessageInTransit::bytes()) + num_bytes, |
- 0, |
+ memset(static_cast<char*>(MessageInTransit::bytes()) + num_bytes, 0, |
main_buffer_size_ - sizeof(Header) - num_bytes); |
} else { |
memset(MessageInTransit::bytes(), 0, main_buffer_size_ - sizeof(Header)); |
@@ -195,7 +195,7 @@ void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) { |
void MessageInTransit::ConstructorHelper(Type type, |
Subtype subtype, |
uint32_t num_bytes) { |
- DCHECK_LE(num_bytes, kMaxMessageNumBytes); |
+ DCHECK_LE(num_bytes, GetConfiguration().max_message_num_bytes); |
// |total_size| is updated below, from the other values. |
header()->type = type; |