Patchwork [6/7] linux-user: Support setgroups syscall with no groups

login
register
mail settings
Submitter riku.voipio@linaro.org
Date March 7, 2013, 10:21 a.m.
Message ID <35c4acdb963b9a8188f101d404dc50b47babd7ea.1362651161.git.riku.voipio@linaro.org>
Download mbox | patch
Permalink /patch/225792/
State New
Headers show

Comments

riku.voipio@linaro.org - March 7, 2013, 10:21 a.m.
From: Dillon Amburgey <dillona@dillona.com>

Signed-off-by: Dillon Amburgey <dillona@dillona.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/syscall.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7f12563..e0c71fb 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7694,18 +7694,20 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         {
             int gidsetsize = arg1;
             target_id *target_grouplist;
-            gid_t *grouplist;
+            gid_t *grouplist = NULL;
             int i;
-
-            grouplist = alloca(gidsetsize * sizeof(gid_t));
-            target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 2, 1);
-            if (!target_grouplist) {
-                ret = -TARGET_EFAULT;
-                goto fail;
+            if (gidsetsize) {
+                grouplist = alloca(gidsetsize * sizeof(gid_t));
+                target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 2, 1);
+                if (!target_grouplist) {
+                    ret = -TARGET_EFAULT;
+                    goto fail;
+                }
+                for (i = 0; i < gidsetsize; i++) {
+                    grouplist[i] = low2highgid(tswapid(target_grouplist[i]));
+                }
+                unlock_user(target_grouplist, arg2, 0);
             }
-            for(i = 0;i < gidsetsize; i++)
-                grouplist[i] = low2highgid(tswapid(target_grouplist[i]));
-            unlock_user(target_grouplist, arg2, 0);
             ret = get_errno(setgroups(gidsetsize, grouplist));
         }
         break;