OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 "ipc/file_descriptor_set_posix.h" | 5 #include "ipc/file_descriptor_set_posix.h" |
6 | 6 |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 | 9 |
10 #include "base/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // message should have been transmitted, then closing those with close | 23 // message should have been transmitted, then closing those with close |
24 // flags set mirrors the expected behaviour. | 24 // flags set mirrors the expected behaviour. |
25 // | 25 // |
26 // If this message was received with more descriptors than expected | 26 // If this message was received with more descriptors than expected |
27 // (which could a DOS against the browser by a rogue renderer) then all | 27 // (which could a DOS against the browser by a rogue renderer) then all |
28 // the descriptors have their close flag set and we free all the extra | 28 // the descriptors have their close flag set and we free all the extra |
29 // kernel resources. | 29 // kernel resources. |
30 for (unsigned i = consumed_descriptor_highwater_; | 30 for (unsigned i = consumed_descriptor_highwater_; |
31 i < descriptors_.size(); ++i) { | 31 i < descriptors_.size(); ++i) { |
32 if (descriptors_[i].auto_close) | 32 if (descriptors_[i].auto_close) |
33 HANDLE_EINTR(close(descriptors_[i].fd)); | 33 if (HANDLE_EINTR(close(descriptors_[i].fd)) < 0) |
| 34 PLOG(ERROR) << "close"; |
34 } | 35 } |
35 } | 36 } |
36 | 37 |
37 bool FileDescriptorSet::Add(int fd) { | 38 bool FileDescriptorSet::Add(int fd) { |
38 if (descriptors_.size() == MAX_DESCRIPTORS_PER_MESSAGE) | 39 if (descriptors_.size() == MAX_DESCRIPTORS_PER_MESSAGE) |
39 return false; | 40 return false; |
40 | 41 |
41 struct base::FileDescriptor sd; | 42 struct base::FileDescriptor sd; |
42 sd.fd = fd; | 43 sd.fd = fd; |
43 sd.auto_close = false; | 44 sd.auto_close = false; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return true; | 107 return true; |
107 } | 108 } |
108 | 109 |
109 return false; | 110 return false; |
110 } | 111 } |
111 | 112 |
112 void FileDescriptorSet::CommitAll() { | 113 void FileDescriptorSet::CommitAll() { |
113 for (std::vector<base::FileDescriptor>::iterator | 114 for (std::vector<base::FileDescriptor>::iterator |
114 i = descriptors_.begin(); i != descriptors_.end(); ++i) { | 115 i = descriptors_.begin(); i != descriptors_.end(); ++i) { |
115 if (i->auto_close) | 116 if (i->auto_close) |
116 HANDLE_EINTR(close(i->fd)); | 117 if (HANDLE_EINTR(close(i->fd)) < 0) |
| 118 PLOG(ERROR) << "close"; |
117 } | 119 } |
118 descriptors_.clear(); | 120 descriptors_.clear(); |
119 consumed_descriptor_highwater_ = 0; | 121 consumed_descriptor_highwater_ = 0; |
120 } | 122 } |
121 | 123 |
122 void FileDescriptorSet::SetDescriptors(const int* buffer, unsigned count) { | 124 void FileDescriptorSet::SetDescriptors(const int* buffer, unsigned count) { |
123 DCHECK_LE(count, MAX_DESCRIPTORS_PER_MESSAGE); | 125 DCHECK_LE(count, MAX_DESCRIPTORS_PER_MESSAGE); |
124 DCHECK_EQ(descriptors_.size(), 0u); | 126 DCHECK_EQ(descriptors_.size(), 0u); |
125 DCHECK_EQ(consumed_descriptor_highwater_, 0u); | 127 DCHECK_EQ(consumed_descriptor_highwater_, 0u); |
126 | 128 |
127 descriptors_.reserve(count); | 129 descriptors_.reserve(count); |
128 for (unsigned i = 0; i < count; ++i) { | 130 for (unsigned i = 0; i < count; ++i) { |
129 struct base::FileDescriptor sd; | 131 struct base::FileDescriptor sd; |
130 sd.fd = buffer[i]; | 132 sd.fd = buffer[i]; |
131 sd.auto_close = true; | 133 sd.auto_close = true; |
132 descriptors_.push_back(sd); | 134 descriptors_.push_back(sd); |
133 } | 135 } |
134 } | 136 } |
OLD | NEW |