diff options
author | Dean Deng <deandeng@google.com> | 2020-12-30 15:20:34 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-12-30 15:22:35 -0800 |
commit | 4691a8125370d61ccb9732574e97ccc26362af42 (patch) | |
tree | 55fc815241983a6cdbc2f852fe382268b81c73c2 /test | |
parent | 899b9ba46a69094975b4f25c24a3c467c0c21276 (diff) |
Add test for open(2) with O_WRONLY|O_RDWR.
PiperOrigin-RevId: 349607959
Diffstat (limited to 'test')
-rw-r--r-- | test/syscalls/linux/open.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/syscalls/linux/open.cc b/test/syscalls/linux/open.cc index 77f390f3c..fcd162ca2 100644 --- a/test/syscalls/linux/open.cc +++ b/test/syscalls/linux/open.cc @@ -505,6 +505,18 @@ TEST_F(OpenTest, OpenNonDirectoryWithTrailingSlash) { EXPECT_THAT(open(bad_path.c_str(), O_RDONLY), SyscallFailsWithErrno(ENOTDIR)); } +TEST_F(OpenTest, OpenWithStrangeFlags) { + // VFS1 incorrectly allows read/write operations on such file descriptors. + SKIP_IF(IsRunningWithVFS1()); + + const TempPath file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile()); + const FileDescriptor fd = + ASSERT_NO_ERRNO_AND_VALUE(Open(file.path(), O_WRONLY | O_RDWR)); + EXPECT_THAT(write(fd.get(), "x", 1), SyscallFailsWithErrno(EBADF)); + char c; + EXPECT_THAT(read(fd.get(), &c, 1), SyscallFailsWithErrno(EBADF)); +} + } // namespace } // namespace testing |