OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 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, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 std::vector<std::string>* vector_annotations) const { | 60 std::vector<std::string>* vector_annotations) const { |
61 mach_vm_address_t crash_info_address; | 61 mach_vm_address_t crash_info_address; |
62 const process_types::section* crash_info_section = | 62 const process_types::section* crash_info_section = |
63 image_reader_->GetSectionByName( | 63 image_reader_->GetSectionByName( |
64 SEG_DATA, "__crash_info", &crash_info_address); | 64 SEG_DATA, "__crash_info", &crash_info_address); |
65 if (!crash_info_section) { | 65 if (!crash_info_section) { |
66 return; | 66 return; |
67 } | 67 } |
68 | 68 |
69 process_types::crashreporter_annotations_t crash_info; | 69 process_types::crashreporter_annotations_t crash_info; |
70 if (crash_info_section->size < crash_info.ExpectedSize(process_reader_)) { | |
71 LOG(WARNING) << "small crash info section size " << crash_info_section->size | |
72 << " in " << name_; | |
73 return; | |
74 } | |
75 | |
76 if (!crash_info.Read(process_reader_, crash_info_address)) { | 70 if (!crash_info.Read(process_reader_, crash_info_address)) { |
77 LOG(WARNING) << "could not read crash info from " << name_; | 71 LOG(WARNING) << "could not read crash info from " << name_; |
78 return; | 72 return; |
79 } | 73 } |
80 | 74 |
81 if (crash_info.version != 4) { | 75 if (crash_info.version != 4 && crash_info.version != 5) { |
82 LOG(WARNING) << "unexpected crash info version " << crash_info.version | 76 LOG(WARNING) << "unexpected crash info version " << crash_info.version |
83 << " in " << name_; | 77 << " in " << name_; |
84 return; | 78 return; |
85 } | 79 } |
86 | 80 |
| 81 size_t expected_size = |
| 82 process_types::crashreporter_annotations_t::ExpectedSizeForVersion( |
| 83 process_reader_, crash_info.version); |
| 84 if (crash_info_section->size < expected_size) { |
| 85 LOG(WARNING) << "small crash info section size " << crash_info_section->size |
| 86 << " < " << expected_size << " for version " |
| 87 << crash_info.version << " in " << name_; |
| 88 return; |
| 89 } |
| 90 |
87 // This number was totally made up out of nowhere, but it seems prudent to | 91 // This number was totally made up out of nowhere, but it seems prudent to |
88 // enforce some limit. | 92 // enforce some limit. |
89 const size_t kMaxMessageSize = 1024; | 93 const size_t kMaxMessageSize = 1024; |
90 if (crash_info.message) { | 94 if (crash_info.message) { |
91 std::string message; | 95 std::string message; |
92 if (process_reader_->Memory()-> | 96 if (process_reader_->Memory()->ReadCStringSizeLimited( |
93 ReadCStringSizeLimited( | 97 crash_info.message, kMaxMessageSize, &message)) { |
94 crash_info.message, kMaxMessageSize, &message)) { | |
95 vector_annotations->push_back(message); | 98 vector_annotations->push_back(message); |
96 } else { | 99 } else { |
97 LOG(WARNING) << "could not read crash message in " << name_; | 100 LOG(WARNING) << "could not read crash message in " << name_; |
98 } | 101 } |
99 } | 102 } |
100 | 103 |
101 if (crash_info.message2) { | 104 if (crash_info.message2) { |
102 std::string message; | 105 std::string message; |
103 if (process_reader_->Memory()-> | 106 if (process_reader_->Memory()->ReadCStringSizeLimited( |
104 ReadCStringSizeLimited( | 107 crash_info.message2, kMaxMessageSize, &message)) { |
105 crash_info.message2, kMaxMessageSize, &message)) { | |
106 vector_annotations->push_back(message); | 108 vector_annotations->push_back(message); |
107 } else { | 109 } else { |
108 LOG(WARNING) << "could not read crash message 2 in " << name_; | 110 LOG(WARNING) << "could not read crash message 2 in " << name_; |
109 } | 111 } |
110 } | 112 } |
111 } | 113 } |
112 | 114 |
113 void MachOImageAnnotationsReader::ReadDyldErrorStringAnnotation( | 115 void MachOImageAnnotationsReader::ReadDyldErrorStringAnnotation( |
114 std::vector<std::string>* vector_annotations) const { | 116 std::vector<std::string>* vector_annotations) const { |
115 // dyld stores its error string at the external symbol for |const char | 117 // dyld stores its error string at the external symbol for |const char |
116 // error_string[1024]|. See 10.9.5 dyld-239.4/src/dyld.cpp error_string. | 118 // error_string[1024]|. See 10.9.5 dyld-239.4/src/dyld.cpp error_string. |
117 if (image_reader_->FileType() != MH_DYLINKER) { | 119 if (image_reader_->FileType() != MH_DYLINKER) { |
118 return; | 120 return; |
119 } | 121 } |
120 | 122 |
121 mach_vm_address_t error_string_address; | 123 mach_vm_address_t error_string_address; |
122 if (!image_reader_->LookUpExternalDefinedSymbol("_error_string", | 124 if (!image_reader_->LookUpExternalDefinedSymbol("_error_string", |
123 &error_string_address)) { | 125 &error_string_address)) { |
124 return; | 126 return; |
125 } | 127 } |
126 | 128 |
127 std::string message; | 129 std::string message; |
128 // 1024 here is distinct from kMaxMessageSize above, because it refers to a | 130 // 1024 here is distinct from kMaxMessageSize above, because it refers to a |
129 // precisely-sized buffer inside dyld. | 131 // precisely-sized buffer inside dyld. |
130 if (process_reader_->Memory()-> | 132 if (process_reader_->Memory()->ReadCStringSizeLimited( |
131 ReadCStringSizeLimited(error_string_address, 1024, &message)) { | 133 error_string_address, 1024, &message)) { |
132 if (!message.empty()) { | 134 if (!message.empty()) { |
133 vector_annotations->push_back(message); | 135 vector_annotations->push_back(message); |
134 } | 136 } |
135 } else { | 137 } else { |
136 LOG(WARNING) << "could not read dylinker error string from " << name_; | 138 LOG(WARNING) << "could not read dylinker error string from " << name_; |
137 } | 139 } |
138 } | 140 } |
139 | 141 |
140 void MachOImageAnnotationsReader::ReadCrashpadSimpleAnnotations( | 142 void MachOImageAnnotationsReader::ReadCrashpadSimpleAnnotations( |
141 std::map<std::string, std::string>* simple_map_annotations) const { | 143 std::map<std::string, std::string>* simple_map_annotations) const { |
142 process_types::CrashpadInfo crashpad_info; | 144 process_types::CrashpadInfo crashpad_info; |
143 if (!image_reader_->GetCrashpadInfo(&crashpad_info)) { | 145 if (!image_reader_->GetCrashpadInfo(&crashpad_info)) { |
144 return; | 146 return; |
145 } | 147 } |
146 | 148 |
147 if (!crashpad_info.simple_annotations) { | 149 if (!crashpad_info.simple_annotations) { |
148 return; | 150 return; |
149 } | 151 } |
150 | 152 |
151 std::vector<SimpleStringDictionary::Entry> | 153 std::vector<SimpleStringDictionary::Entry> |
152 simple_annotations(SimpleStringDictionary::num_entries); | 154 simple_annotations(SimpleStringDictionary::num_entries); |
153 if (!process_reader_->Memory() | 155 if (!process_reader_->Memory()->Read( |
154 ->Read(crashpad_info.simple_annotations, | 156 crashpad_info.simple_annotations, |
155 simple_annotations.size() * sizeof(simple_annotations[0]), | 157 simple_annotations.size() * sizeof(simple_annotations[0]), |
156 &simple_annotations[0])) { | 158 &simple_annotations[0])) { |
157 LOG(WARNING) << "could not read simple annotations from " << name_; | 159 LOG(WARNING) << "could not read simple annotations from " << name_; |
158 return; | 160 return; |
159 } | 161 } |
160 | 162 |
161 for (const auto& entry : simple_annotations) { | 163 for (const auto& entry : simple_annotations) { |
162 size_t key_length = strnlen(entry.key, sizeof(entry.key)); | 164 size_t key_length = strnlen(entry.key, sizeof(entry.key)); |
163 if (key_length) { | 165 if (key_length) { |
164 std::string key(entry.key, key_length); | 166 std::string key(entry.key, key_length); |
165 std::string value(entry.value, strnlen(entry.value, sizeof(entry.value))); | 167 std::string value(entry.value, strnlen(entry.value, sizeof(entry.value))); |
166 if (!simple_map_annotations->insert(std::make_pair(key, value)).second) { | 168 if (!simple_map_annotations->insert(std::make_pair(key, value)).second) { |
167 LOG(INFO) << "duplicate simple annotation " << key << " in " << name_; | 169 LOG(INFO) << "duplicate simple annotation " << key << " in " << name_; |
168 } | 170 } |
169 } | 171 } |
170 } | 172 } |
171 } | 173 } |
172 | 174 |
173 } // namespace crashpad | 175 } // namespace crashpad |
OLD | NEW |