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

Side by Side Diff: util/mach/mach_message.cc

Issue 1001943002: handler/mac: Log a warning when an exception message has a suspicious (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 9 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
OLDNEW
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,
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 "util/mach/mach_message.h" 15 #include "util/mach/mach_message.h"
16 16
17 #include <AvailabilityMacros.h>
18 #include <bsm/libbsm.h>
19
17 #include <limits> 20 #include <limits>
18 21
19 #include "base/basictypes.h" 22 #include "base/basictypes.h"
23 #include "base/logging.h"
20 #include "util/misc/clock.h" 24 #include "util/misc/clock.h"
21 25
22 namespace crashpad { 26 namespace crashpad {
23 27
24 namespace { 28 namespace {
25 29
26 const int kNanosecondsPerMillisecond = 1E6; 30 const int kNanosecondsPerMillisecond = 1E6;
27 31
28 // TimerRunning() determines whether |deadline| has passed. If |deadline| is 32 // TimerRunning() determines whether |deadline| has passed. If |deadline| is
29 // kMachMessageDeadlineWaitIndefinitely, |*timeout_options| is set to 33 // kMachMessageDeadlineWaitIndefinitely, |*timeout_options| is set to
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 reinterpret_cast<mig_reply_error_t*>(out_header)->RetCode = error; 210 reinterpret_cast<mig_reply_error_t*>(out_header)->RetCode = error;
207 } 211 }
208 212
209 const mach_msg_trailer_t* MachMessageTrailerFromHeader( 213 const mach_msg_trailer_t* MachMessageTrailerFromHeader(
210 const mach_msg_header_t* header) { 214 const mach_msg_header_t* header) {
211 vm_address_t header_address = reinterpret_cast<vm_address_t>(header); 215 vm_address_t header_address = reinterpret_cast<vm_address_t>(header);
212 vm_address_t trailer_address = header_address + round_msg(header->msgh_size); 216 vm_address_t trailer_address = header_address + round_msg(header->msgh_size);
213 return reinterpret_cast<const mach_msg_trailer_t*>(trailer_address); 217 return reinterpret_cast<const mach_msg_trailer_t*>(trailer_address);
214 } 218 }
215 219
220 pid_t AuditPIDFromMachMessageTrailer(const mach_msg_trailer_t* trailer) {
221 if (trailer->msgh_trailer_type != MACH_MSG_TRAILER_FORMAT_0) {
222 LOG(ERROR) << "unexpected msgh_trailer_type " << trailer->msgh_trailer_type;
223 return -1;
224 }
225 if (trailer->msgh_trailer_size <
226 REQUESTED_TRAILER_SIZE(
227 MACH_RCV_TRAILER_TYPE(MACH_MSG_TRAILER_FORMAT_0) |
228 MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT))) {
229 LOG(ERROR) << "small msgh_trailer_size " << trailer->msgh_trailer_size;
230 return -1;
231 }
232
233 const mach_msg_audit_trailer_t* audit_trailer =
234 reinterpret_cast<const mach_msg_audit_trailer_t*>(trailer);
235
236 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
237 pid_t audit_pid;
238 audit_token_to_au32(audit_trailer->msgh_audit,
239 nullptr,
240 nullptr,
241 nullptr,
242 nullptr,
243 nullptr,
244 &audit_pid,
245 nullptr,
246 nullptr);
247 #else
248 pid_t audit_pid = audit_token_to_pid(audit_trailer->msgh_audit);
249 #endif
250
251 return audit_pid;
252 }
253
216 } // namespace crashpad 254 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698