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

Side by Side Diff: mojo/edk/system/channel.cc

Issue 1940353002: [mojo-edk] Invalidate message handle when rewrite fails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/embedder/platform_handle_utils_win.cc ('k') | mojo/edk/system/node_channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process, 324 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process,
325 base::ProcessHandle to_process, 325 base::ProcessHandle to_process,
326 PlatformHandle* handles, 326 PlatformHandle* handles,
327 size_t num_handles) { 327 size_t num_handles) {
328 bool success = true; 328 bool success = true;
329 for (size_t i = 0; i < num_handles; ++i) { 329 for (size_t i = 0; i < num_handles; ++i) {
330 if (!handles[i].is_valid()) { 330 if (!handles[i].is_valid()) {
331 DLOG(ERROR) << "Refusing to duplicate invalid handle."; 331 DLOG(ERROR) << "Refusing to duplicate invalid handle.";
332 continue; 332 continue;
333 } 333 }
334 CHECK_NE(handles[i].handle, INVALID_HANDLE_VALUE);
Ken Rockot(use gerrit already) 2016/05/03 16:46:49 Just noticing that this can't be reached given the
334 DCHECK_EQ(handles[i].owning_process, from_process); 335 DCHECK_EQ(handles[i].owning_process, from_process);
335 BOOL result = DuplicateHandle( 336 BOOL result = DuplicateHandle(
336 from_process, handles[i].handle, to_process, 337 from_process, handles[i].handle, to_process,
337 &handles[i].handle, 0, FALSE, 338 &handles[i].handle, 0, FALSE,
338 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); 339 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
339 if (result) 340 if (result) {
340 handles[i].owning_process = to_process; 341 handles[i].owning_process = to_process;
341 else 342 } else {
342 success = false; 343 success = false;
344
345 // If handle duplication fails, the source handle will already be closed
346 // due to DUPLICATE_CLOSE_SOURCE. Replace the handle in the message with
347 // an invalid handle.
348 handles[i].handle = INVALID_HANDLE_VALUE;
349 handles[i].owning_process = base::GetCurrentProcessHandle();
350 }
343 } 351 }
344 return success; 352 return success;
345 } 353 }
346 #endif 354 #endif
347 355
348 // Helper class for managing a Channel's read buffer allocations. This maintains 356 // Helper class for managing a Channel's read buffer allocations. This maintains
349 // a single contiguous buffer with the layout: 357 // a single contiguous buffer with the layout:
350 // 358 //
351 // [discarded bytes][occupied bytes][unoccupied bytes] 359 // [discarded bytes][occupied bytes][unoccupied bytes]
352 // 360 //
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 return true; 569 return true;
562 } 570 }
563 571
564 void Channel::OnError() { 572 void Channel::OnError() {
565 if (delegate_) 573 if (delegate_)
566 delegate_->OnChannelError(); 574 delegate_->OnChannelError();
567 } 575 }
568 576
569 } // namespace edk 577 } // namespace edk
570 } // namespace mojo 578 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_handle_utils_win.cc ('k') | mojo/edk/system/node_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698