diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-05-21 14:41:42 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-05-21 15:33:43 -0700 |
commit | 31e46743abc894a70e420411e7d183e8ef0f8e45 (patch) | |
tree | c25c4ea4c1aef408c02a4f08e3ec9b4f5dabd445 /tests/altstack-util.h | |
parent | 9c4b4b083f87a3075d92dd72d5aa4a0007edb5ee (diff) | |
download | gnulib-31e46743abc894a70e420411e7d183e8ef0f8e45.tar.gz |
sigsegv: don’t assume SIGSTKSZ is a constant
* m4/sigaltstack.m4 (SV_SIGALTSTACK): Don’t attempt to override
SIGSTKSZ. Instead, use an array that is plenty large, while
checking that it’s large enough. Also, be consistent about
putting that array in static storage rather than on the stack.
* tests/altstack-util.h (SIGSTKSZ): Don’t define.
(MYSTACK_SIZE): New macro, used consistently instead of SIGSTKSZ.
(mystack_storage, mystack): Now static.
(prepare_alternate_stack) [defined SIGSTKSZ]:
Check that MYSTACK_SIZE is large enough.
Diffstat (limited to 'tests/altstack-util.h')
-rw-r--r-- | tests/altstack-util.h | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/tests/altstack-util.h b/tests/altstack-util.h index 5130645064..f91072611c 100644 --- a/tests/altstack-util.h +++ b/tests/altstack-util.h @@ -18,9 +18,7 @@ #include <stdint.h> /* uintptr_t */ #include <string.h> /* for memset */ -#ifndef SIGSTKSZ -# define SIGSTKSZ 16384 -#endif +#define MYSTACK_SIZE (1 << 24) /* glibc says: Users should use SIGSTKSZ as the size of user-supplied buffers. We want to detect stack overflow of the alternate stack @@ -29,12 +27,20 @@ an unaligned pointer, to ensure the alternate stack still ends up aligned. */ #define MYSTACK_CRUMPLE_ZONE 8192 -char mystack_storage[SIGSTKSZ + 2 * MYSTACK_CRUMPLE_ZONE + 31]; -char *mystack; /* SIGSTKSZ bytes in the middle of storage. */ +static char mystack_storage[MYSTACK_SIZE + 2 * MYSTACK_CRUMPLE_ZONE + 31]; +static char *mystack; /* MYSTACK_SIZE bytes in the middle of storage. */ static void prepare_alternate_stack (void) { +#ifdef SIGSTKSZ + if (MYSTACK_SIZE < SIGSTKSZ) + { + size_t size = SIGSTKSZ; + printf ("SIGSTKSZ=%zu exceeds MYSTACK_SIZE=%d\n", size, MYSTACK_SIZE); + exit (1); + } +#endif memset (mystack_storage, 's', sizeof mystack_storage); mystack = (char *) ((uintptr_t) (mystack_storage + MYSTACK_CRUMPLE_ZONE) | 31); } @@ -51,7 +57,7 @@ check_alternate_stack_no_overflow (void) exit (1); } for (i = MYSTACK_CRUMPLE_ZONE; i > 0; i--) - if (*(mystack + SIGSTKSZ - 1 + i) != 's') + if (*(mystack + MYSTACK_SIZE - 1 + i) != 's') { printf ("Alternate stack was exceeded by %u bytes!!\n", i); exit (1); |