mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.97k stars 332 forks source link

`cd` builtin doesn't work if your group doesn't match the directory's group #1033

Closed theclapp closed 9 months ago

theclapp commented 9 months ago

The cd builtin checks whether your user ID can read a directory, or whether your actual group ID can read a directory, or whether "others" can read a directory, but it doesn't check the other groups your ID may be a member of.

% id
uid=1001(lmc) gid=1001(lmc) groups=1001(lmc),27(sudo),998(vboxsf)

% ls -ld host
drwxrwx--- 1 root vboxsf 640 Sep 16 03:48 host/

% cd host
=> error 1

It looks like you need to check user.User.GroupIds() (https://pkg.go.dev/os/user#User.GroupIds) too/instead.