Skip to content

Commit 5d215b5

Browse files
committed
interp: fix cd builtin: check all user groups
Fixes mvdan#1033.
1 parent 698a968 commit 5d215b5

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

interp/os_unix.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,26 @@ func hasPermissionToDir(info os.FileInfo) bool {
4343
return true
4444
}
4545

46+
// Group perms only apply if you're not the owner of the directory.
4647
gid, _ := strconv.Atoi(user.Gid)
47-
// other users in group (g)
48-
if perm&0o010 != 0 && st.Uid != uint32(uid) && st.Gid == uint32(gid) {
49-
return true
48+
inGroup := st.Gid == uint32(gid)
49+
if st.Uid != uint32(uid) {
50+
gids, _ := user.GroupIds()
51+
for _, gid := range gids {
52+
gid, _ := strconv.Atoi(gid)
53+
if st.Gid == uint32(gid) {
54+
// other users in group (g)
55+
if perm&0o010 != 0 {
56+
return true
57+
}
58+
inGroup = true
59+
}
60+
}
5061
}
51-
// remaining users (o)
52-
if perm&0o001 != 0 && st.Uid != uint32(uid) && st.Gid != uint32(gid) {
62+
63+
// remaining users (o) -- only apply if you're not the owner and none of
64+
// your groups match its group.
65+
if perm&0o001 != 0 && st.Uid != uint32(uid) && !inGroup {
5366
return true
5467
}
5568

0 commit comments

Comments
 (0)