qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [patch] fix getgroups and getgroups32 syscalls
@ 2007-12-07 23:17 Lauro Ramos Venancio
  2007-12-08 12:50 ` Kirill A. Shutemov
  0 siblings, 1 reply; 2+ messages in thread
From: Lauro Ramos Venancio @ 2007-12-07 23:17 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 354 bytes --]

The attached patch fixes a bug in getgroups and getgroups32 syscalls.
The current implementation returns error when size=0.

According the manual:
" If size is zero, list is not modified, but the total number of
supplementary group IDs for the process is returned."

--
Lauro Ramos Venancio
OpenBossa Labs - Instituto Nokia de Tecnologia
Recife - Brazil

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 00_fix_getgroups.patch --]
[-- Type: text/x-patch; name=00_fix_getgroups.patch, Size: 1608 bytes --]

Index: qemu-arm-eabi/linux-user/syscall.c
===================================================================
--- qemu-arm-eabi.orig/linux-user/syscall.c	2007-12-07 19:59:03.000000000 -0300
+++ qemu-arm-eabi/linux-user/syscall.c	2007-12-07 20:01:47.000000000 -0300
@@ -5024,12 +5024,13 @@
         {
             int gidsetsize = arg1;
             uint16_t *target_grouplist;
-            gid_t *grouplist;
+            gid_t *grouplist = NULL;
             int i;
 
-            grouplist = alloca(gidsetsize * sizeof(gid_t));
+            if (gidsetsize)
+                grouplist = alloca(gidsetsize * sizeof(gid_t));
             ret = get_errno(getgroups(gidsetsize, grouplist));
-            if (!is_error(ret)) {
+            if (gidsetsize && !is_error(ret)) {
                 target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0);
                 if (!target_grouplist)
                     goto efault;
@@ -5174,12 +5175,13 @@
         {
             int gidsetsize = arg1;
             uint32_t *target_grouplist;
-            gid_t *grouplist;
+            gid_t *grouplist = NULL;
             int i;
 
-            grouplist = alloca(gidsetsize * sizeof(gid_t));
+            if (gidsetsize)
+                grouplist = alloca(gidsetsize * sizeof(gid_t));
             ret = get_errno(getgroups(gidsetsize, grouplist));
-            if (!is_error(ret)) {
+            if (gidsetsize && !is_error(ret)) {
                 target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0);
                 if (!target_grouplist) {
                     ret = -TARGET_EFAULT;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [patch] fix getgroups and getgroups32 syscalls
  2007-12-07 23:17 [Qemu-devel] [patch] fix getgroups and getgroups32 syscalls Lauro Ramos Venancio
@ 2007-12-08 12:50 ` Kirill A. Shutemov
  0 siblings, 0 replies; 2+ messages in thread
From: Kirill A. Shutemov @ 2007-12-08 12:50 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2654 bytes --]

On [Fri, 07.12.2007 20:17], Lauro Ramos Venancio wrote:
> The attached patch fixes a bug in getgroups and getgroups32 syscalls.
> The current implementation returns error when size=0.
> 
> According the manual:
> " If size is zero, list is not modified, but the total number of
> supplementary group IDs for the process is returned."
> 
> --
> Lauro Ramos Venancio
> OpenBossa Labs - Instituto Nokia de Tecnologia
> Recife - Brazil

> Index: qemu-arm-eabi/linux-user/syscall.c
> ===================================================================
> --- qemu-arm-eabi.orig/linux-user/syscall.c	2007-12-07 19:59:03.000000000 -0300
> +++ qemu-arm-eabi/linux-user/syscall.c	2007-12-07 20:01:47.000000000 -0300
> @@ -5024,12 +5024,13 @@
>          {
>              int gidsetsize = arg1;
>              uint16_t *target_grouplist;
> -            gid_t *grouplist;
> +            gid_t *grouplist = NULL;
>              int i;
>  
> -            grouplist = alloca(gidsetsize * sizeof(gid_t));
> +            if (gidsetsize)
> +                grouplist = alloca(gidsetsize * sizeof(gid_t));
>              ret = get_errno(getgroups(gidsetsize, grouplist));
> -            if (!is_error(ret)) {
> +            if (gidsetsize && !is_error(ret)) {
>                  target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0);
>                  if (!target_grouplist)
>                      goto efault;

This patch is too noisy, I think. My patch:

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ad97871..96a11a9 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5029,6 +5029,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 
             grouplist = alloca(gidsetsize * sizeof(gid_t));
             ret = get_errno(getgroups(gidsetsize, grouplist));
+            if (gidsetsize == 0)
+                break;
             if (!is_error(ret)) {
                 target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 2, 0);
                 if (!target_grouplist)
@@ -5179,6 +5181,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 
             grouplist = alloca(gidsetsize * sizeof(gid_t));
             ret = get_errno(getgroups(gidsetsize, grouplist));
+            if (gidsetsize == 0)
+                break;
             if (!is_error(ret)) {
                 target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0);
                 if (!target_grouplist) {



-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + Velesys LLC, http://www.velesys.com/
 + ALT Linux Team, http://www.altlinux.com/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-12-08 12:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-07 23:17 [Qemu-devel] [patch] fix getgroups and getgroups32 syscalls Lauro Ramos Venancio
2007-12-08 12:50 ` Kirill A. Shutemov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).