From 7ccb0b6a7cd7fa33f2d58484aed5cfe1709018ca Mon Sep 17 00:00:00 2001 From: Adin Scannell Date: Wed, 2 Dec 2020 10:46:10 -0800 Subject: Fix chown test. PiperOrigin-RevId: 345265342 --- test/syscalls/linux/chown.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/syscalls/linux/chown.cc b/test/syscalls/linux/chown.cc index 82223f997..5530ad18f 100644 --- a/test/syscalls/linux/chown.cc +++ b/test/syscalls/linux/chown.cc @@ -75,7 +75,16 @@ TEST_P(ChownParamTest, ChownFileSucceeds) { if (num_groups > 0) { std::vector list(num_groups); EXPECT_THAT(getgroups(list.size(), list.data()), SyscallSucceeds()); - gid = list[0]; + // Scan the list of groups for a valid gid. Note that if a group is not + // defined in this local user namespace, then we will see 65534, and the + // group will not chown below as expected. So only change if we find a + // valid group in this list. + for (const gid_t other_gid : list) { + if (other_gid != 65534) { + gid = other_gid; + break; + } + } } EXPECT_NO_ERRNO(GetParam()(file.path(), geteuid(), gid)); -- cgit v1.2.3