Mercurial > hg > octave-kai > gnulib-hg
changeset 10471:f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
* m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Make
recursion harder to optimize, to ensure a stack overflow occurs.
* tests/test-c-stack.c (recurse): Likewise.
Borrowed from libsigsegv.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Tue, 23 Sep 2008 08:56:10 -0600 |
parents | 9867f4fee019 |
children | a4dc39a18d54 |
files | ChangeLog m4/c-stack.m4 tests/test-c-stack.c |
diffstat | 3 files changed, 45 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-09-23 Eric Blake <ebb9@byu.net> + c-stack: avoid compiler optimizations when provoking overflow + * m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Make + recursion harder to optimize, to ensure a stack overflow occurs. + * tests/test-c-stack.c (recurse): Likewise. + Borrowed from libsigsegv. + c-stack: work around Irix sigaltstack bug * m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Check whether sigaltstack uses wrong end of stack_t (copied in part from
--- a/m4/c-stack.m4 +++ b/m4/c-stack.m4 @@ -64,15 +64,19 @@ act.sa_handler = segv_handler; return sigaction (SIGSEGV, &act, 0); } - - static int - recurse (char *p) + static volatile int * + recurse_1 (volatile int n, volatile int *p) { - char array[500]; - array[0] = 1; - return *p + recurse (array); + if (n >= 0) + *recurse_1 (n + 1, p) += n; + return p; } - + static int + recurse (volatile int n) + { + int sum = 0; + return *recurse_1 (n, &sum); + } int main () { @@ -86,7 +90,7 @@ setrlimit (RLIMIT_STACK, &rl); #endif - return c_stack_action () || recurse ("\1"); + return c_stack_action () || recurse (0); } ], [ac_cv_sys_stack_overflow_works=yes], @@ -242,15 +246,19 @@ act.sa_sigaction = segv_handler; return sigaction (SIGSEGV, &act, 0); } - - static int - recurse (char *p) + static volatile int * + recurse_1 (volatile int n, volatile int *p) { - char array[500]; - array[0] = 1; - return *p + recurse (array); + if (n >= 0) + *recurse_1 (n + 1, p) += n; + return p; } - + static int + recurse (volatile int n) + { + int sum = 0; + return *recurse_1 (n, &sum); + } int main () { @@ -264,7 +272,7 @@ setrlimit (RLIMIT_STACK, &rl); #endif - return c_stack_action () || recurse ("\1"); + return c_stack_action () || recurse (0); } ], [ac_cv_sys_xsi_stack_overflow_heuristic=yes],
--- a/tests/test-c-stack.c +++ b/tests/test-c-stack.c @@ -41,15 +41,22 @@ } \ while (0) -static long -recurse (char *p) +char *program_name; + +static volatile int * +recurse_1 (volatile int n, volatile int *p) { - char array[500]; - array[0] = 1; - return *p + recurse (array); + if (n >= 0) + *recurse_1 (n + 1, p) += n; + return p; } -char *program_name; +static int +recurse (volatile int n) +{ + int sum = 0; + return *recurse_1 (n, &sum); +} int main (int argc, char **argv) @@ -72,8 +79,9 @@ exit_failure = 77; ++*argv[argc]; /* Intentionally dereference NULL. */ } - return recurse ("\1"); + return recurse (0); } + fputs ("skipping test: ", stderr); perror ("c_stack_action"); return 77; }