Fix //test/syscalls:exec_test_native

Later kernels add empty arguments to argv, throwing off return values for the
exec_basic_workload.cc binary. This is result of a bug introduced by
ccbb18b67323b "exec/binfmt_script: Don't modify bprm->buf and then return -
ENOEXEC". Before this change, an empty interpreter string was reported if the
first non-space/non-tab character after "#!" was '\0' (end of file, previously-
overwritten trailing space or tab, or previously-overwritten first newline).
After this change, an empty interpreter string is reported if all characters
after "#!" are spaces or tabs, or the first non-space non-tab character is at
i_end, which is the position of the first newline after "#!". However, if
there is no newline after "#!" (as in ExecTest.InterpreterScriptNoPath),
then i_end = buf_end (= bprm->buf + sizeof(bprm->buf) - 1, the last possible
byte in the buffer) and neither condition holds.

Change white space for script inputs to take into account the above bug.

Co-authored-by: Andrei Vagin <avagin@gmail.com>
PiperOrigin-RevId: 378997171
This commit is contained in:
Zach Koopmans
2021-06-11 20:33:58 -07:00
committed by gVisor bot
co-authored by Andrei Vagin
parent ec6a7ebc75
commit b92e8ee8d6
2 changed files with 6 additions and 9 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ func parseInterpreterScript(ctx context.Context, filename string, f fsbridge.Fil
// Linux silently truncates the remainder of the line if it exceeds
// interpMaxLineLength.
i := bytes.IndexByte(line, '\n')
if i > 0 {
if i >= 0 {
line = line[:i]
}
+5 -8
View File
@@ -278,15 +278,12 @@ TEST(ExecTest, InterpreterScriptArgNUL) {
// Trailing whitespace following interpreter path is ignored.
TEST(ExecTest, InterpreterScriptTrailingWhitespace) {
// FIXME(b/190850365): This test case fails on Linux.
SKIP_IF(!IsRunningOnGvisor());
// Symlink through /tmp to ensure the path is short enough.
TempPath link = ASSERT_NO_ERRNO_AND_VALUE(
TempPath::CreateSymlinkTo("/tmp", RunfilePath(kBasicWorkload)));
TempPath script = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileWith(
GetAbsoluteTestTmpdir(), absl::StrCat("#!", link.path(), " "), 0755));
GetAbsoluteTestTmpdir(), absl::StrCat("#!", link.path(), " \n"), 0755));
CheckExec(script.path(), {script.path()}, {}, ArgEnvExitStatus(1, 0),
absl::StrCat(link.path(), "\n", script.path(), "\n"));
@@ -306,11 +303,11 @@ TEST(ExecTest, InterpreterScriptArgWhitespace) {
}
TEST(ExecTest, InterpreterScriptNoPath) {
// FIXME(b/190850365): This test case fails on Linux.
SKIP_IF(!IsRunningOnGvisor());
TempPath script = ASSERT_NO_ERRNO_AND_VALUE(
TempPath::CreateFileWith(GetAbsoluteTestTmpdir(), "#!", 0755));
TempPath::CreateFileWith(GetAbsoluteTestTmpdir(), "#!\n\n", 0755));
std::cerr << "path: " << script.path() << std::endl;
std::cerr << system(absl::StrCat("cat ", script.path()).c_str()) << std::endl;
int execve_errno;
ASSERT_NO_ERRNO_AND_VALUE(