diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2019-07-01 15:24:18 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-07-01 15:25:22 -0700 |
commit | 06537129a67cbdced394f514a7d2399c19082f47 (patch) | |
tree | 2c925f789c745f661c4000c4084309144ea576ad /test/syscalls/linux | |
parent | 3446f4e29bd547e5576caf16d8c2bb45560439e9 (diff) |
Check remaining traversal limit when creating a file through a symlink.
This fixes the case when an app tries to create a file that already exists, and
is a symlink to itself. A test was added.
PiperOrigin-RevId: 256044811
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r-- | test/syscalls/linux/symlink.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/syscalls/linux/symlink.cc b/test/syscalls/linux/symlink.cc index dce8de9ec..69650a1d3 100644 --- a/test/syscalls/linux/symlink.cc +++ b/test/syscalls/linux/symlink.cc @@ -312,6 +312,19 @@ TEST_P(ParamSymlinkTest, OpenLinkCreatesTarget) { ASSERT_THAT(unlink(target.c_str()), SyscallSucceeds()); } +// Test that opening a self-symlink with O_CREAT will fail with ELOOP. +TEST_P(ParamSymlinkTest, CreateExistingSelfLink) { + ASSERT_THAT(chdir(GetAbsoluteTestTmpdir().c_str()), SyscallSucceeds()); + + const std::string linkpath = GetParam(); + ASSERT_THAT(symlink(linkpath.c_str(), linkpath.c_str()), SyscallSucceeds()); + + EXPECT_THAT(open(linkpath.c_str(), O_CREAT, 0666), + SyscallFailsWithErrno(ELOOP)); + + ASSERT_THAT(unlink(linkpath.c_str()), SyscallSucceeds()); +} + // Test that opening an existing symlink with O_CREAT|O_EXCL will fail with // EEXIST. TEST_P(ParamSymlinkTest, OpenLinkExclFails) { |