]> sourceware.org Git - lvm2.git/commitdiff
fix: limit preallocate stack size
authorZdenek Kabelac <zkabelac@redhat.com>
Fri, 22 Jun 2012 09:15:14 +0000 (11:15 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Fri, 22 Jun 2012 11:48:04 +0000 (13:48 +0200)
If the user would set bigger reserved stack size then what
is allowed in resources (ulimit -s), then he would get coredump
So avoid coredump and ignore creation of such large stack size
(lvm should work properly, with just 64KB, so the option could
be eliminated).

lib/mm/memlock.c

index 17dee1c9024bf53179b1c35b0148498021044ecb..dfc0d42b13f951e6387d333e6357a4c909d79955 100644 (file)
@@ -124,8 +124,12 @@ static void _touch_memory(void *mem, size_t size)
 static void _allocate_memory(void)
 {
        void *stack_mem, *temp_malloc_mem;
+       struct rlimit limit;
 
-       if ((stack_mem = alloca(_size_stack)))
+       /* Check if we could preallocate requested stack */
+       if ((getrlimit (RLIMIT_STACK, &limit) == 0) &&
+           ((_size_stack * 2) < limit.rlim_cur) &&
+           ((stack_mem = alloca(_size_stack))))
                _touch_memory(stack_mem, _size_stack);
 
        if ((temp_malloc_mem = malloc(_size_malloc_tmp)))
This page took 0.029517 seconds and 5 git commands to generate.