Index: sandbox/linux/services/broker_process_unittest.cc |
diff --git a/sandbox/linux/services/broker_process_unittest.cc b/sandbox/linux/services/broker_process_unittest.cc |
index 7f1a685fe11cbac269e0157e7a0c6825756d3f44..1c77c36ff02316400a65c5fa8a0503bee527d69f 100644 |
--- a/sandbox/linux/services/broker_process_unittest.cc |
+++ b/sandbox/linux/services/broker_process_unittest.cc |
@@ -21,6 +21,7 @@ |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/posix/eintr_wrapper.h" |
+#include "base/posix/unix_domain_socket_linux.h" |
#include "sandbox/linux/tests/test_utils.h" |
#include "sandbox/linux/tests/unit_tests.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -434,4 +435,38 @@ TEST(BrokerProcess, OpenComplexFlagsNoClientCheck) { |
// expected. |
} |
+// We need to allow noise because the broker will log when it receives our |
+// bogus IPCs. |
+SANDBOX_TEST_ALLOW_NOISE(BrokerProcess, RecvMsgDescriptorLeak) { |
+ // Find the lowest available file descriptor currently. |
+ const int min_fd = dup(STDIN_FILENO); |
jln (very slow on Chromium)
2014/04/09 02:25:47
Maybe just create a pipe or open cpuinfo instead?
jln (very slow on Chromium)
2014/04/09 02:25:47
While dup(2) will always give you the smallest fd
jln (very slow on Chromium)
2014/04/09 02:32:09
I meant "by setting soft rlimit and trying to dup(
mdempsky
2014/04/09 23:29:40
Changed to use pipes.
mdempsky
2014/04/09 23:29:40
True. I've reworked this to be more robust about
|
+ SANDBOX_ASSERT(min_fd >= 0); |
+ SANDBOX_ASSERT(0 == IGNORE_EINTR(close(min_fd))); |
+ |
+ // Lower our file descriptor limit to just above the current limit so we can |
jln (very slow on Chromium)
2014/04/09 02:25:47
You mean just above the current usage I think?
|
+ // test for descriptor leaks easier. |
+ const unsigned kExtraFiles = 8; |
+ const struct rlimit new_rlim = {min_fd + kExtraFiles, min_fd + kExtraFiles}; |
+ SANDBOX_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &new_rlim)); |
+ |
+ const char kCpuInfo[] = "/proc/cpuinfo"; |
+ std::vector<std::string> read_whitelist; |
+ read_whitelist.push_back(kCpuInfo); |
+ |
+ BrokerProcess open_broker(EPERM, read_whitelist, std::vector<std::string>()); |
+ SANDBOX_ASSERT(open_broker.Init(base::Bind(&NoOpCallback))); |
+ |
+ static const char kBogus[] = "not a pickle"; |
+ const std::vector<int> fds(1, STDIN_FILENO); |
+ |
+ for (unsigned i = 0; i < kExtraFiles; ++i) { |
+ SANDBOX_ASSERT(UnixDomainSocket::SendMsg( |
+ open_broker.ipc_socketpair(), kBogus, sizeof(kBogus), fds)); |
+ } |
+ |
+ const int fd = open_broker.Open(kCpuInfo, O_RDONLY); |
+ SANDBOX_ASSERT(fd >= 0); |
+ SANDBOX_ASSERT(0 == IGNORE_EINTR(close(fd))); |
+} |
+ |
} // namespace sandbox |