forkserver: Remove order dependent tests

Sending -1 as fd will fail and take forkserver down.
This should not happen normally so turned it into a check.

PiperOrigin-RevId: 285391908
Change-Id: Idbb05004c36cb0be57be1bd26df1c57cecfb0019
This commit is contained in:
Wiktor Garbacz 2019-12-13 06:58:21 -08:00 committed by Copybara-Service
parent 4608a7baea
commit 7125458c5d
2 changed files with 3 additions and 13 deletions

View File

@ -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);

View File

@ -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