summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2019-07-08 14:56:09 -0700
committergVisor bot <gvisor-bot@google.com>2019-07-08 14:57:15 -0700
commit6db3f8d54c0225e6b6c3d8eef30b4b61498848b7 (patch)
treeee85d7855e9cd6dde7ee8de443a04e5c0f317ae8 /test/syscalls/linux
parente45d724948cf03a7aca871971e75f2cfe1a3bc1f (diff)
Don't mask errors in createAt loop.
The error set in the loop in createAt was being masked by other errors declared with ":=". This allowed an ErrResolveViaReadlink error to escape, which can cause a sentry panic. Added test case which repros without the fix. PiperOrigin-RevId: 257061767
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r--test/syscalls/linux/symlink.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/syscalls/linux/symlink.cc b/test/syscalls/linux/symlink.cc
index 69650a1d3..b249ff91f 100644
--- a/test/syscalls/linux/symlink.cc
+++ b/test/syscalls/linux/symlink.cc
@@ -325,6 +325,21 @@ TEST_P(ParamSymlinkTest, CreateExistingSelfLink) {
ASSERT_THAT(unlink(linkpath.c_str()), SyscallSucceeds());
}
+// Test that opening a file that is a symlink to its parent directory fails
+// with ELOOP.
+TEST_P(ParamSymlinkTest, CreateExistingParentLink) {
+ ASSERT_THAT(chdir(GetAbsoluteTestTmpdir().c_str()), SyscallSucceeds());
+
+ const std::string linkpath = GetParam();
+ const std::string target = JoinPath(linkpath, "child");
+ ASSERT_THAT(symlink(target.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) {