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

Unified Diff: util/mach/mach_message_test.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: MACH_MSG_TYPE_MAKE_SEND_ONCE 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/mach/mach_message.cc ('k') | util/mach/notify_server_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/mach/mach_message_test.cc
diff --git a/util/mach/mach_message_test.cc b/util/mach/mach_message_test.cc
index 9877e2d1343dfc22f220abd999ef385cefd8f629..578195a3a4d862a1586e1bf0ea6c88a5b2901123 100644
--- a/util/mach/mach_message_test.cc
+++ b/util/mach/mach_message_test.cc
@@ -14,9 +14,13 @@
#include "util/mach/mach_message.h"
+#include <unistd.h>
+
#include "base/basictypes.h"
+#include "base/mac/scoped_mach_port.h"
#include "gtest/gtest.h"
#include "util/mach/mach_extensions.h"
+#include "util/test/mac/mach_errors.h"
namespace crashpad {
namespace test {
@@ -104,6 +108,46 @@ TEST(MachMessage, MachMessageTrailerFromHeader) {
EXPECT_EQ(&test.receive.trailer, MachMessageTrailerFromHeader(&test.receive));
}
+TEST(MachMessage, AuditPIDFromMachMessageTrailer) {
+ base::mac::ScopedMachReceiveRight port(NewMachPort(MACH_PORT_RIGHT_RECEIVE));
+ ASSERT_NE(kMachPortNull, port);
+
+ mach_msg_empty_send_t send = {};
+ send.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND_ONCE, 0);
+ send.header.msgh_size = sizeof(send);
+ send.header.msgh_remote_port = port;
+ mach_msg_return_t mr =
+ MachMessageWithDeadline(&send.header,
+ MACH_SEND_MSG,
+ 0,
+ MACH_PORT_NULL,
+ kMachMessageDeadlineNonblocking,
+ MACH_PORT_NULL,
+ false);
+ ASSERT_EQ(MACH_MSG_SUCCESS, mr)
+ << MachErrorMessage(mr, "MachMessageWithDeadline send");
+
+ struct EmptyReceiveMessageWithAuditTrailer : public mach_msg_empty_send_t {
+ union {
+ mach_msg_trailer_t trailer;
+ mach_msg_audit_trailer_t audit_trailer;
+ };
+ };
+
+ EmptyReceiveMessageWithAuditTrailer receive;
+ mr = MachMessageWithDeadline(&receive.header,
+ MACH_RCV_MSG | kMachMessageReceiveAuditTrailer,
+ sizeof(receive),
+ port,
+ kMachMessageDeadlineNonblocking,
+ MACH_PORT_NULL,
+ false);
+ ASSERT_EQ(MACH_MSG_SUCCESS, mr)
+ << MachErrorMessage(mr, "MachMessageWithDeadline receive");
+
+ EXPECT_EQ(getpid(), AuditPIDFromMachMessageTrailer(&receive.trailer));
+}
+
} // namespace
} // namespace test
} // namespace crashpad
« no previous file with comments | « util/mach/mach_message.cc ('k') | util/mach/notify_server_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698