From 79931797441bc166c7381ef7865f139e5cdb47e8 Mon Sep 17 00:00:00 2001 From: des Date: Sat, 19 Jul 2014 20:55:13 +0000 Subject: Check if the specified group is the user's primary group before iterating over the (possibly empty) list of members. Otherwise, we get a false negative when the target group has no members listed in /etc/group. This went mostly unnoticed because root is explicitly listed as a member of wheel, so the bug is never triggered in the most common use case, which is su(8). PR: 109416 MFC after: 1 week --- lib/libpam/modules/pam_group/pam_group.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/libpam/modules/pam_group/pam_group.c b/lib/libpam/modules/pam_group/pam_group.c index a6e32cd..5b918c0 100644 --- a/lib/libpam/modules/pam_group/pam_group.c +++ b/lib/libpam/modules/pam_group/pam_group.c @@ -96,14 +96,12 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags __unused, if ((grp = getgrnam(group)) == NULL || grp->gr_mem == NULL) goto failed; - /* check if the group is empty */ - if (*grp->gr_mem == NULL) - goto failed; - - /* check membership */ + /* check if user's own primary group */ if (pwd->pw_gid == grp->gr_gid) goto found; - for (list = grp->gr_mem; *list != NULL; ++list) + + /* iterate over members */ + for (list = grp->gr_mem; list != NULL && *list != NULL; ++list) if (strcmp(*list, pwd->pw_name) == 0) goto found; -- cgit v1.1