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

Side by Side Diff: chrome/common/ipc_channel_posix.cc

Issue 20275: POSIX: Clean up DescriptorSet (Closed)
Patch Set: ... Created 11 years, 10 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 | « chrome/common/descriptor_set_posix.cc ('k') | chrome/common/ipc_message.h » ('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 (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 "chrome/common/ipc_channel_posix.h" 5 #include "chrome/common/ipc_channel_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 memcpy(&input_overflow_fds_[prev_size], wire_fds, 476 memcpy(&input_overflow_fds_[prev_size], wire_fds,
477 num_wire_fds * sizeof(int)); 477 num_wire_fds * sizeof(int));
478 fds = &input_overflow_fds_[0]; 478 fds = &input_overflow_fds_[0];
479 num_fds = input_overflow_fds_.size(); 479 num_fds = input_overflow_fds_.size();
480 } 480 }
481 481
482 while (p < end) { 482 while (p < end) {
483 const char* message_tail = Message::FindNext(p, end); 483 const char* message_tail = Message::FindNext(p, end);
484 if (message_tail) { 484 if (message_tail) {
485 int len = static_cast<int>(message_tail - p); 485 int len = static_cast<int>(message_tail - p);
486 const Message m(p, len); 486 Message m(p, len);
487 if (m.header()->num_fds) { 487 if (m.header()->num_fds) {
488 // the message has file descriptors 488 // the message has file descriptors
489 const char* error = NULL;
489 if (m.header()->num_fds > num_fds - fds_i) { 490 if (m.header()->num_fds > num_fds - fds_i) {
490 // the message has been completely received, but we didn't get 491 // the message has been completely received, but we didn't get
491 // enough file descriptors. 492 // enough file descriptors.
492 LOG(WARNING) << "Message needs unreceived descriptors" 493 error = "Message needs unreceived descriptors";
494 }
495
496 if (m.header()->num_fds >
497 DescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE) {
498 // There are too many descriptors in this message
499 error = "Message requires an excessive number of descriptors";
500 }
501
502 if (error) {
503 LOG(WARNING) << error
493 << " channel:" << this 504 << " channel:" << this
494 << " message-type:" << m.type() 505 << " message-type:" << m.type()
495 << " header()->num_fds:" << m.header()->num_fds 506 << " header()->num_fds:" << m.header()->num_fds
496 << " num_fds:" << num_fds 507 << " num_fds:" << num_fds
497 << " fds_i:" << fds_i; 508 << " fds_i:" << fds_i;
498 // close the existing file descriptors so that we don't leak them 509 // close the existing file descriptors so that we don't leak them
499 for (unsigned i = fds_i; i < num_fds; ++i) 510 for (unsigned i = fds_i; i < num_fds; ++i)
500 close(fds[i]); 511 close(fds[i]);
501 input_overflow_fds_.clear(); 512 input_overflow_fds_.clear();
513 // abort the connection
502 return false; 514 return false;
503 } 515 }
504 516
505 m.descriptor_set()->SetDescriptors(&fds[fds_i], m.header()->num_fds); 517 m.descriptor_set()->SetDescriptors(&fds[fds_i], m.header()->num_fds);
506 fds_i += m.header()->num_fds; 518 fds_i += m.header()->num_fds;
507 } 519 }
508 #ifdef IPC_MESSAGE_DEBUG_EXTRA 520 #ifdef IPC_MESSAGE_DEBUG_EXTRA
509 DLOG(INFO) << "received message on channel @" << this << 521 DLOG(INFO) << "received message on channel @" << this <<
510 " with type " << m.type(); 522 " with type " << m.type();
511 #endif 523 #endif
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 void Channel::GetClientFileDescriptorMapping(int *src_fd, int *dest_fd) { 803 void Channel::GetClientFileDescriptorMapping(int *src_fd, int *dest_fd) {
792 return channel_impl_->GetClientFileDescriptorMapping(src_fd, dest_fd); 804 return channel_impl_->GetClientFileDescriptorMapping(src_fd, dest_fd);
793 } 805 }
794 806
795 void Channel::OnClientConnected() { 807 void Channel::OnClientConnected() {
796 return channel_impl_->OnClientConnected(); 808 return channel_impl_->OnClientConnected();
797 } 809 }
798 810
799 811
800 } // namespace IPC 812 } // namespace IPC
OLDNEW
« no previous file with comments | « chrome/common/descriptor_set_posix.cc ('k') | chrome/common/ipc_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698