k9core

Coreutils for *nix operating systems
git clone git://bvnf.space/k9core.git
Log | Files | Refs | LICENSE

commit 1d0891f7d8a4569f69cc9cf2f018be8c8996442c
parent 35afd689286a9771d63cde57389af4451f821e10
Author: aabacchus <ben@bvnf.space>
Date:   Tue, 14 Sep 2021 17:14:36 +0100

groups: fix segfault by mallocing enough space

Diffstat:
Msrc/groups.c | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/groups.c b/src/groups.c @@ -24,10 +24,12 @@ main(int argc, char *argv[]) } int ngroups = 10; - uid_t *groups = malloc(ngroups); + gid_t *groups = malloc(ngroups * sizeof(*groups)); if(getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ngroups) == -1) { /* the user is a member of more than ngroups groups */ - return 1; + ngroups += 10; + groups = malloc(ngroups * sizeof(*groups)); + getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ngroups); } struct group *gr; for(int i = 0; i < ngroups; i++) { @@ -35,5 +37,6 @@ main(int argc, char *argv[]) printf("%s ", gr->gr_name); } printf("\n"); + free(groups); return 0; }