Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Oct 2014 05:39:42 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r273684 - head/sys/kern
Message-ID:  <201410260539.s9Q5dgQH081655@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Sun Oct 26 05:39:42 2014
New Revision: 273684
URL: https://svnweb.freebsd.org/changeset/base/273684

Log:
  Use a temporary buffer in sys_setgroups for requests with <= XU_NGROUPS groups.
  
  Submitted by:	Tiwei Bie <btw mail.ustc.edu.cn>
  X-Additional: JuniorJobs project
  MFC after:	2 weeks

Modified:
  head/sys/kern/kern_prot.c

Modified: head/sys/kern/kern_prot.c
==============================================================================
--- head/sys/kern/kern_prot.c	Sun Oct 26 04:44:28 2014	(r273683)
+++ head/sys/kern/kern_prot.c	Sun Oct 26 05:39:42 2014	(r273684)
@@ -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);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410260539.s9Q5dgQH081655>