Skip to content

Commit

Permalink
Mojo: Linux channel break out of loop on read fail
Browse files Browse the repository at this point in the history
Make sure we break out of both loops on read issues.

Bug: chromium:1175855
Change-Id: I979a06bb526fe32a03be5bfe5d04f737518e3646
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2907112
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: Brian Geffon <bgeffon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#885046}
  • Loading branch information
bgaff authored and Chromium LUCI CQ committed May 20, 2021
1 parent d8dd5da commit 3f86025
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mojo/core/channel_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -778,14 +778,14 @@ void ChannelLinux::SharedMemReadReady() {
CHECK(read_buffer_);
if (read_buffer_->TryLockForReading()) {
read_notifier_->Clear();
bool read_fail = false;
do {
uint32_t bytes_read = 0;
SharedBuffer::Error read_res = read_buffer_->TryReadLocked(
read_buf_.data(), read_buf_.size(), &bytes_read);
if (read_res == SharedBuffer::Error::kControlCorruption) {
// This is an error we cannot recover from.
OnError(Error::kReceivedMalformedData);
read_buffer_->UnlockForReading();
break;
}

Expand All @@ -809,6 +809,7 @@ void ChannelLinux::SharedMemReadReady() {
// full message if we get one something has gone horribly wrong.
if (result != DispatchResult::kOK) {
LOG(ERROR) << "Recevied a bad message via shared memory";
read_fail = true;
OnError(Error::kReceivedMalformedData);
break;
}
Expand All @@ -819,7 +820,7 @@ void ChannelLinux::SharedMemReadReady() {
// starts.
data_offset += read_size_hint;
}
} while (true);
} while (!read_fail);
read_buffer_->UnlockForReading();
}
}
Expand Down

0 comments on commit 3f86025

Please sign in to comment.