diff --git a/sandboxed_api/sandbox2/forkserver.cc b/sandboxed_api/sandbox2/forkserver.cc index afbef40..ab16ee7 100644 --- a/sandboxed_api/sandbox2/forkserver.cc +++ b/sandboxed_api/sandbox2/forkserver.cc @@ -189,6 +189,7 @@ pid_t ForkClient::SendRequest(const ForkRequest& request, int exec_fd, SAPI_RAW_LOG(ERROR, "Sending PB to the ForkServer failed"); return -1; } + SAPI_RAW_CHECK(comms_fd != -1, "comms_fd was not properly set up"); if (!comms_->SendFD(comms_fd)) { SAPI_RAW_LOG(ERROR, "Sending Comms FD (%d) to the ForkServer failed", comms_fd); @@ -196,6 +197,7 @@ pid_t ForkClient::SendRequest(const ForkRequest& request, int exec_fd, } if (request.mode() == FORKSERVER_FORK_EXECVE || request.mode() == FORKSERVER_FORK_EXECVE_SANDBOX) { + SAPI_RAW_CHECK(exec_fd != -1, "exec_fd cannot be -1 in execve mode"); if (!comms_->SendFD(exec_fd)) { SAPI_RAW_LOG(ERROR, "Sending Exec FD (%d) to the ForkServer failed", exec_fd); @@ -204,6 +206,7 @@ pid_t ForkClient::SendRequest(const ForkRequest& request, int exec_fd, } if (request.mode() == FORKSERVER_FORK_JOIN_SANDBOX_UNWIND) { + SAPI_RAW_CHECK(user_ns_fd != -1, "user_ns_fd cannot be -1 in unwind mode"); if (!comms_->SendFD(user_ns_fd)) { SAPI_RAW_LOG(ERROR, "Sending user ns FD (%d) to the ForkServer failed", user_ns_fd); diff --git a/sandboxed_api/sandbox2/forkserver_test.cc b/sandboxed_api/sandbox2/forkserver_test.cc index 6cc87f8..3750a3e 100644 --- a/sandboxed_api/sandbox2/forkserver_test.cc +++ b/sandboxed_api/sandbox2/forkserver_test.cc @@ -104,19 +104,6 @@ TEST(ForkserverTest, ForkExecveSandboxWithoutPolicy) { // Run a test binary through the FORKSERVER_FORK_EXECVE_SANDBOX request. int exec_fd = GetMinimalTestcaseFd(); PCHECK(exec_fd != -1) << "Could not open test binary"; - ASSERT_NE(TestSingleRequest(FORKSERVER_FORK_EXECVE_SANDBOX, exec_fd, -1), -1); -} - -TEST(ForkserverTest, ForkExecveRequiresExecFD) { - // This test should generate some warnings: - // (Sending Exec FD (-1) to the ForkServer failed). - ASSERT_EQ(TestSingleRequest(FORKSERVER_FORK_EXECVE, -1, -1), -1); -} - -TEST(ForkserverTest, ForkExecveSandboxRequiresExecFD) { - // This test should generate some warnings: - // (Sending Exec FD (-1) to the ForkServer failed). - ASSERT_EQ(TestSingleRequest(FORKSERVER_FORK_EXECVE_SANDBOX, -1, -1), -1); } } // namespace sandbox2