[PATCH] NGROUPS_MAX will cause stack overflow

Aubrey aubreylee at gmail.com
Wed Dec 28 04:10:23 UTC 2005


On 12/27/05, Mike Frysinger <vapier at gentoo.org> wrote:
> thanks, ive committed a slightly different version of this as well
> -mike
>
Oops, just now I found my patch has problem when malloc(0). The
original implement will return a valid value when n=0. But my patch
depents on the behavior of malloc. When uClibc option [Malloc returns
live pointer for malloc(0)] is enabled, my patch will return a valid
value. But when it is disabled, my patch will return (-1).

This case should be handled like this:

- if(kernel_groups=(__kernel_gid_t *)malloc(sizeof(__kernel_gid_t)*n) == NULL){
+if( (kernel_groups=(__kernel_gid_t *)malloc(sizeof(__kernel_gid_t)*n) == NULL)
+     && n!=0 ) {

                       __set_errno(EINVAL);
                       return -1;
               }
Now it should be exactly correct.
We also tested it and worked fine.

Thanks
-Aubrey



More information about the uClibc mailing list