Date: Sun, 26 Oct 2014 12:08:19 +0800 From: Tiwei Bie <btw@mail.ustc.edu.cn> To: mjg@freebsd.org Cc: freebsd-hackers@freebsd.org Subject: [PATCH] Finish the task 'Temporary buffer in setgroups' Message-ID: <1414296499-55792-1-git-send-email-btw@mail.ustc.edu.cn>
next in thread | raw e-mail | index | archive | help
Hi, mjg! I have finished the task: Temporary buffer in setgroups [1]. Following is my patch: diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index f12468d..73f6ab7 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -806,17 +806,24 @@ int sys_setgroups(struct thread *td, struct setgroups_args *uap) { gid_t *groups = NULL; + gid_t smallgroups[XU_NGROUPS]; + u_int gidsetsize; int error; - if (uap->gidsetsize > ngroups_max + 1) + gidsetsize = uap->gidsetsize; + if (gidsetsize > ngroups_max + 1) return (EINVAL); - groups = malloc(uap->gidsetsize * sizeof(gid_t), M_TEMP, M_WAITOK); - error = copyin(uap->gidset, groups, uap->gidsetsize * sizeof(gid_t)); + if (gidsetsize > XU_NGROUPS) + groups = malloc(gidsetsize * sizeof(gid_t), M_TEMP, M_WAITOK); + else + groups = smallgroups; + error = copyin(uap->gidset, groups, gidsetsize * sizeof(gid_t)); if (error) goto out; - error = kern_setgroups(td, uap->gidsetsize, groups); + error = kern_setgroups(td, gidsetsize, groups); out: - free(groups, M_TEMP); + if (gidsetsize > XU_NGROUPS) + free(groups, M_TEMP); return (error); } -- 2.1.0 [1] https://wiki.freebsd.org/JuniorJobs#Temporary_buffer_in_setgroups Tiwei Bie
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1414296499-55792-1-git-send-email-btw>