Skip to content

Commit

Permalink
Mojo: Force crash when sending oversized messages
Browse files Browse the repository at this point in the history
This causes a CHECK failure when any process attempts to send a message
which exceeds the maxmimum allowed message size.

We used to only validate message size on receipt and shoot the sending
Channel if receiving an oversized message. We still do, but we used to,
too.

This change should make it much easier to identify offending code
responsible for sending oversized messages in any process type.

BUG=758902

Change-Id: I1a175f25d3e2f0be4ef9a8dc2af1b46ba282fa0c
Reviewed-on: https://chromium-review.googlesource.com/666082
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501844}
  • Loading branch information
krockot authored and Commit Bot committed Sep 14, 2017
1 parent 69ac1e4 commit 0d4eb8a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mojo/edk/system/node_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "mojo/edk/system/channel.h"
#include "mojo/edk/system/configuration.h"
#include "mojo/edk/system/request_context.h"

#if defined(OS_MACOSX) && !defined(OS_IOS)
Expand Down Expand Up @@ -907,6 +908,12 @@ void NodeChannel::WriteChannelMessage(Channel::MessagePtr message) {
}
#endif

// Force a crash if this process attempts to send a message larger than the
// maximum allowed size. This is more useful than killing a Channel when we
// *receive* an oversized message, as we should consider oversized message
// transmission to be a bug and this helps easily identify offending code.
CHECK(message->data_num_bytes() < GetConfiguration().max_message_num_bytes);

base::AutoLock lock(channel_lock_);
if (!channel_)
DLOG(ERROR) << "Dropping message on closed channel.";
Expand Down

0 comments on commit 0d4eb8a

Please sign in to comment.