[lxc-devel] [PATCH] namespace: check stack allocation for clone succeeds

Michael Santos michael.santos at gmail.com
Mon Apr 11 21:09:04 UTC 2011


On Mon, Apr 11, 2011 at 12:42:49PM -0500, Nathan Lynch wrote:
> On Mon, 2011-04-11 at 12:42 -0400, Michael Santos wrote:
> > ---
> >  src/lxc/namespace.c |    7 ++++++-
> >  1 files changed, 6 insertions(+), 1 deletions(-)
> > 
> > diff --git a/src/lxc/namespace.c b/src/lxc/namespace.c
> > index 8263fe7..5928eaa 100644
> > --- a/src/lxc/namespace.c
> > +++ b/src/lxc/namespace.c
> > @@ -67,9 +67,14 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags)
> >  	};
> >  
> >  	long stack_size = sysconf(_SC_PAGESIZE);
> > - 	void *stack = alloca(stack_size) + stack_size;
> > +	void *stack = alloca(stack_size);
> >  	pid_t ret;
> >  
> > +	if (stack == NULL)
> > +		ERROR("failed to allocate memory");
> > +
> > +	stack += stack_size;
> > +
> 
> Please see the man page, in particular "Notes on the GNU Version" and
> "BUGS", for why this patch doesn't really make sense.
> 
> http://www.kernel.org/doc/man-pages/online/pages/man3/alloca.3.html

And I was sure I checked the man page and it said NULL is returned :)

Thank you for the correction!





More information about the lxc-devel mailing list