From d4652bd6dfd3a7ed086c4fd134ded1bee8cf1f32 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Thu, 12 May 2022 17:46:13 -0700 Subject: [PATCH] Use syscall() for fchmod() calls Avoids Bionic when running on Android. See https://android-review.googlesource.com/c/platform/bionic/+/127908 PiperOrigin-RevId: 448378850 --- test/syscalls/linux/chmod.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/syscalls/linux/chmod.cc b/test/syscalls/linux/chmod.cc index f5ae8f926..3c6bc7234 100644 --- a/test/syscalls/linux/chmod.cc +++ b/test/syscalls/linux/chmod.cc @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -102,7 +103,11 @@ TEST(ChmodTest, FchmodFileWithOpath) { auto file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile()); FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(Open(file.path(), O_PATH)); - ASSERT_THAT(fchmod(fd.get(), 0444), SyscallFailsWithErrno(EBADF)); + // Bionic's implementation of fchmod() uses chmod() when O_PATH is set + // to circumvent the behavior this is testing for. + // Use syscall() here to avoid running through Bionic on Android. + ASSERT_THAT(syscall(SYS_fchmod, fd.get(), 0444), + SyscallFailsWithErrno(EBADF)); } TEST(ChmodTest, FchmodDirWithOpath) { @@ -110,7 +115,8 @@ TEST(ChmodTest, FchmodDirWithOpath) { const auto fd = ASSERT_NO_ERRNO_AND_VALUE(Open(dir.path(), O_DIRECTORY | O_PATH)); - ASSERT_THAT(fchmod(fd.get(), 0444), SyscallFailsWithErrno(EBADF)); + ASSERT_THAT(syscall(SYS_fchmod, fd.get(), 0444), + SyscallFailsWithErrno(EBADF)); } TEST(ChmodTest, FchmodatWithOpath) {