]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslogins: ask for supplementary groups only once [asan]
authorKarel Zak <kzak@redhat.com>
Thu, 22 Jul 2021 09:30:22 +0000 (11:30 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 22 Jul 2021 09:30:22 +0000 (11:30 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/lslogins.c

index cf1b8e7cafb79a3ce6d5103253853d935aa5cbb1..f07d83ecc19cbcb45d99dc79f5302151d864bb97 100644 (file)
@@ -562,6 +562,9 @@ static int get_sgroups(gid_t **list, size_t *len, struct passwd *pwd)
 
        *list = xcalloc(1, ngroups * sizeof(gid_t));
 
+fprintf(stderr, "KZAK>>> alloc '%p' for %s\n", *list, pwd->pw_name);
+
+
        /* now for the actual list of GIDs */
        if (-1 == getgrouplist(pwd->pw_name, pwd->pw_gid, *list, &ngroups))
                return -1;
@@ -754,7 +757,8 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
                        break;
                case COL_SGROUPS:
                case COL_SGIDS:
-                       if (get_sgroups(&user->sgroups, &user->nsgroups, pwd))
+                       if (!user->nsgroups &&
+                           get_sgroups(&user->sgroups, &user->nsgroups, pwd) < 0)
                                err(EXIT_FAILURE, _("failed to get supplementary groups"));
                        break;
                case COL_HOME:
@@ -1048,7 +1052,6 @@ static int create_usertree(struct lslogins_control *ctl)
                        }
                        if (rc || !user)
                                continue;
-
                        tsearch(user, &ctl->usertree, cmp_uid);
                }
        } else {