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

Unified Diff: util/mach/exception_ports_test.cc

Issue 1381023007: mac: Don’t leak send rights from ExceptionPorts::GetExceptionPorts() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 2 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/exception_ports.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/mach/exception_ports_test.cc
diff --git a/util/mach/exception_ports_test.cc b/util/mach/exception_ports_test.cc
index 478dfe219dbb4e8db60ecb6dc5cafe2539761213..7384c022015aaa7a9c24f2b29e2c79babb3194e1 100644
--- a/util/mach/exception_ports_test.cc
+++ b/util/mach/exception_ports_test.cc
@@ -64,13 +64,12 @@ void TestGetExceptionPorts(const ExceptionPorts& exception_ports,
? THREAD_STATE_NONE
: MACHINE_THREAD_STATE;
- std::vector<ExceptionPorts::ExceptionHandler> crash_handler;
+ ExceptionPorts::ExceptionHandlerVector crash_handler;
ASSERT_TRUE(
exception_ports.GetExceptionPorts(kExceptionMask, &crash_handler));
if (expect_port != MACH_PORT_NULL) {
ASSERT_EQ(1u, crash_handler.size());
- base::mac::ScopedMachSendRight port_owner(crash_handler[0].port);
EXPECT_EQ(kExceptionMask, crash_handler[0].mask);
EXPECT_EQ(expect_port, crash_handler[0].port);
@@ -80,15 +79,13 @@ void TestGetExceptionPorts(const ExceptionPorts& exception_ports,
EXPECT_TRUE(crash_handler.empty());
}
- std::vector<ExceptionPorts::ExceptionHandler> handlers;
+ ExceptionPorts::ExceptionHandlerVector handlers;
ASSERT_TRUE(exception_ports.GetExceptionPorts(ExcMaskValid(), &handlers));
EXPECT_GE(handlers.size(), crash_handler.size());
bool found = false;
for (const ExceptionPorts::ExceptionHandler& handler : handlers) {
if ((handler.mask & kExceptionMask) != 0) {
- base::mac::ScopedMachSendRight port_owner(handler.port);
-
EXPECT_FALSE(found);
found = true;
EXPECT_EQ(expect_port, handler.port);
@@ -586,28 +583,27 @@ TEST(ExceptionPorts, HostExceptionPorts) {
// host_set_exception_ports() is not tested, because if the test were running
// as root and the call succeeded, it would have global effects.
+ const bool expect_success = geteuid() == 0;
+
base::mac::ScopedMachSendRight host(mach_host_self());
ExceptionPorts explicit_host_ports(ExceptionPorts::kTargetTypeHost, host);
EXPECT_STREQ("host", explicit_host_ports.TargetTypeName());
- std::vector<ExceptionPorts::ExceptionHandler> handlers;
- bool rv = explicit_host_ports.GetExceptionPorts(ExcMaskValid(), &handlers);
- if (geteuid() == 0) {
- EXPECT_TRUE(rv);
- } else {
- EXPECT_FALSE(rv);
- }
+ ExceptionPorts::ExceptionHandlerVector explicit_handlers;
+ bool rv =
+ explicit_host_ports.GetExceptionPorts(ExcMaskValid(), &explicit_handlers);
+ EXPECT_EQ(expect_success, rv);
ExceptionPorts implicit_host_ports(ExceptionPorts::kTargetTypeHost,
HOST_NULL);
EXPECT_STREQ("host", implicit_host_ports.TargetTypeName());
- rv = implicit_host_ports.GetExceptionPorts(ExcMaskValid(), &handlers);
- if (geteuid() == 0) {
- EXPECT_TRUE(rv);
- } else {
- EXPECT_FALSE(rv);
- }
+ ExceptionPorts::ExceptionHandlerVector implicit_handlers;
+ rv =
+ implicit_host_ports.GetExceptionPorts(ExcMaskValid(), &implicit_handlers);
+ EXPECT_EQ(expect_success, rv);
+
+ EXPECT_EQ(explicit_handlers.size(), implicit_handlers.size());
}
} // namespace
« no previous file with comments | « util/mach/exception_ports.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698