OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "minidump/minidump_handle_writer.h" | 15 #include "minidump/minidump_handle_writer.h" |
16 | 16 |
17 #include <string> | 17 #include <string> |
18 | 18 |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
21 #include "minidump/minidump_extensions.h" | 21 #include "minidump/minidump_extensions.h" |
22 #include "util/file/file_writer.h" | 22 #include "util/file/file_writer.h" |
| 23 #include "util/numeric/safe_assignment.h" |
23 | 24 |
24 namespace crashpad { | 25 namespace crashpad { |
25 | 26 |
26 MinidumpHandleDataWriter::MinidumpHandleDataWriter() | 27 MinidumpHandleDataWriter::MinidumpHandleDataWriter() |
27 : handle_data_stream_base_(), handle_descriptors_(), strings_() { | 28 : handle_data_stream_base_(), handle_descriptors_(), strings_() { |
28 } | 29 } |
29 | 30 |
30 MinidumpHandleDataWriter::~MinidumpHandleDataWriter() { | 31 MinidumpHandleDataWriter::~MinidumpHandleDataWriter() { |
31 STLDeleteContainerPairSecondPointers(strings_.begin(), strings_.end()); | 32 STLDeleteContainerPairSecondPointers(strings_.begin(), strings_.end()); |
32 } | 33 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 70 } |
70 | 71 |
71 bool MinidumpHandleDataWriter::Freeze() { | 72 bool MinidumpHandleDataWriter::Freeze() { |
72 DCHECK_EQ(state(), kStateMutable); | 73 DCHECK_EQ(state(), kStateMutable); |
73 | 74 |
74 if (!MinidumpStreamWriter::Freeze()) | 75 if (!MinidumpStreamWriter::Freeze()) |
75 return false; | 76 return false; |
76 | 77 |
77 handle_data_stream_base_.SizeOfHeader = sizeof(handle_data_stream_base_); | 78 handle_data_stream_base_.SizeOfHeader = sizeof(handle_data_stream_base_); |
78 handle_data_stream_base_.SizeOfDescriptor = sizeof(handle_descriptors_[0]); | 79 handle_data_stream_base_.SizeOfDescriptor = sizeof(handle_descriptors_[0]); |
79 handle_data_stream_base_.NumberOfDescriptors = handle_descriptors_.size(); | 80 const size_t handle_count = handle_descriptors_.size(); |
| 81 if (!AssignIfInRange(&handle_data_stream_base_.NumberOfDescriptors, |
| 82 handle_count)) { |
| 83 LOG(ERROR) << "handle_count " << handle_count << " out of range"; |
| 84 return false; |
| 85 } |
80 handle_data_stream_base_.Reserved = 0; | 86 handle_data_stream_base_.Reserved = 0; |
81 | 87 |
82 return true; | 88 return true; |
83 } | 89 } |
84 | 90 |
85 size_t MinidumpHandleDataWriter::SizeOfObject() { | 91 size_t MinidumpHandleDataWriter::SizeOfObject() { |
86 DCHECK_GE(state(), kStateFrozen); | 92 DCHECK_GE(state(), kStateFrozen); |
87 return sizeof(handle_data_stream_base_) + | 93 return sizeof(handle_data_stream_base_) + |
88 sizeof(handle_descriptors_[0]) * handle_descriptors_.size(); | 94 sizeof(handle_descriptors_[0]) * handle_descriptors_.size(); |
89 } | 95 } |
(...skipping 22 matching lines...) Expand all Loading... |
112 } | 118 } |
113 | 119 |
114 return file_writer->WriteIoVec(&iovecs); | 120 return file_writer->WriteIoVec(&iovecs); |
115 } | 121 } |
116 | 122 |
117 MinidumpStreamType MinidumpHandleDataWriter::StreamType() const { | 123 MinidumpStreamType MinidumpHandleDataWriter::StreamType() const { |
118 return kMinidumpStreamTypeHandleData; | 124 return kMinidumpStreamTypeHandleData; |
119 } | 125 } |
120 | 126 |
121 } // namespace crashpad | 127 } // namespace crashpad |
OLD | NEW |