getgrouplist duplication of cr_groups[0] as cr_groups[1]

Rick Macklem rmacklem at uoguelph.ca
Wed Jun 3 23:35:57 UTC 2020


Hi,

During testing of a mountd.c patch I have, I found an "old bug" where the
mountd.c code assumed that getgrouplist() would always duplicate
cr_groups[0] in cr_groups[1].

If I read the commit logs correctly, this was always the case until
r174547 (only 12years ago), which switched getgrouplist() to
use __getgroupmembership().
Kirk fixed the deduplication code in gr_addgid() in r328304 so that
gr_addgid() would not deduplicate cr_groups[0,1].
However, the case where the "user" is not also listed in the group
database for the same group as their gid in the password database
will not be duplicated.
--> It also implies that getgrouplist() can return with ngroups == 1,
      with only the basegid in it.

So, is getgrouplist(3) always returning with cr_groups[0] and cr_groups[1]
duplicated required behaviour?

If the duplication is not required, then I can easily fix mountd to
check for the non-duplicated case.
I will probably patch it anyhow, since the one line change will be
harmless even if getgrouplist() is changed to always return the
duplicate of cr_groups[0] in cr_groups[1].

rick



More information about the freebsd-current mailing list