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

Unified Diff: mojo/edk/system/routed_raw_channel.cc

Issue 1537593002: Fix UAF in new Mojo EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improve comment Created 5 years 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/system/message_pipe_dispatcher.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/routed_raw_channel.cc
diff --git a/mojo/edk/system/routed_raw_channel.cc b/mojo/edk/system/routed_raw_channel.cc
index cd57693cbdcd401b3678b09f4595890b593c2ab0..c2b62a77ac36cd216ed842e04f2cd618e105b0c8 100644
--- a/mojo/edk/system/routed_raw_channel.cc
+++ b/mojo/edk/system/routed_raw_channel.cc
@@ -59,7 +59,9 @@ void RoutedRawChannel::AddRoute(uint64_t route_id,
void RoutedRawChannel::RemoveRoute(uint64_t route_id) {
DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread());
- CHECK(routes_.find(route_id) != routes_.end());
+ // We don't check that routes_ contains route_id because it's possible for it
+ // to not have been added yet (i.e. it's waiting to be added later down the
+ // call stack).
routes_.erase(route_id);
// Only send a message to the other side to close the route if we hadn't
@@ -132,24 +134,22 @@ void RoutedRawChannel::OnReadMessage(
void RoutedRawChannel::OnError(Error error) {
DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread());
-
- // This needs to match non-multiplexed MessagePipeDispatcher's destruction of
- // the channel only when read errors occur.
- if (error != ERROR_WRITE || routes_.empty()) {
- channel_->Shutdown();
- channel_ = nullptr;
+
+ // Note: we must ensure we don't call RawChannel::Shutdown until after we've
+ // called OnError on each route's delegate.
+ for (auto it = routes_.begin(); it != routes_.end();) {
+ // The delegate might call RemoveRoute in their OnError implementation which
+ // would invalidate |it|. So increment it first.
+ auto cur_it = it++;
+ cur_it->second->OnError(error);
}
if (routes_.empty()) {
+ channel_->Shutdown();
+ channel_ = nullptr;
delete this;
return;
}
-
- for (auto it = routes_.begin(); it != routes_.end();) {
- // Handle the delegate calling RemoveRoute in this call.
- auto cur_it = it++;
- cur_it->second->OnError(error);
- }
}
} // namespace edk
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698