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

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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DCHECK_EQ(handles[i].owning_process, from_process); 334 DCHECK_EQ(handles[i].owning_process, from_process);
335 BOOL result = DuplicateHandle( 335 BOOL result = DuplicateHandle(
336 from_process, handles[i].handle, to_process, 336 from_process, handles[i].handle, to_process,
337 &handles[i].handle, 0, FALSE, 337 &handles[i].handle, 0, FALSE,
338 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); 338 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
339 if (result) 339 if (result) {
340 handles[i].owning_process = to_process; 340 handles[i].owning_process = to_process;
341 else 341 } else {
342 success = false; 342 success = false;
343
344 // If handle duplication fails, the source handle will already be closed
345 // due to DUPLICATE_CLOSE_SOURCE. Replace the handle in the message with
346 // an invalid handle.
347 handles[i].handle = INVALID_HANDLE_VALUE;
348 handles[i].owning_process = base::GetCurrentProcessHandle();
349 }
343 } 350 }
344 return success; 351 return success;
345 } 352 }
346 #endif 353 #endif
347 354
348 // Helper class for managing a Channel's read buffer allocations. This maintains 355 // Helper class for managing a Channel's read buffer allocations. This maintains
349 // a single contiguous buffer with the layout: 356 // a single contiguous buffer with the layout:
350 // 357 //
351 // [discarded bytes][occupied bytes][unoccupied bytes] 358 // [discarded bytes][occupied bytes][unoccupied bytes]
352 // 359 //
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 return true; 568 return true;
562 } 569 }
563 570
564 void Channel::OnError() { 571 void Channel::OnError() {
565 if (delegate_) 572 if (delegate_)
566 delegate_->OnChannelError(); 573 delegate_->OnChannelError();
567 } 574 }
568 575
569 } // namespace edk 576 } // namespace edk
570 } // namespace mojo 577 } // 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