@@ -279,6 +279,7 @@ tests = \
tst-backtrace6 \
tst-longjmp_chk \
tst-longjmp_chk2 \
+ tst-longjmp_chk3 \
tst-realpath-chk \
tst-sprintf-fortify-unchecked \
# tests
@@ -18,13 +18,13 @@
#include <setjmp.h>
#include <signal.h>
+#include <stdio.h>
#include <string.h>
-static int do_test (void);
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/check.h>
+#include <support/support.h>
+#include <support/xsignal.h>
-static char buf[SIGSTKSZ * 4];
static jmp_buf jb;
static void
@@ -48,19 +48,10 @@ handler (int sig)
static int
do_test (void)
{
- stack_t ss;
-
set_fortify_handler (handler);
/* Create a valid signal stack and enable it. */
- ss.ss_sp = buf;
- ss.ss_size = sizeof (buf);
- ss.ss_flags = 0;
- if (sigaltstack (&ss, NULL) < 0)
- {
- printf ("first sigaltstack failed: %m\n");
- return 1;
- }
+ void *sstk1 = xalloc_sigstack (SIGSTKSZ * 4);
/* Trigger the signal handler which will create a jmpbuf that points to the
end of the signal stack. */
@@ -69,17 +60,15 @@ do_test (void)
/* Shrink the signal stack so the jmpbuf is now invalid.
We adjust the start & end to handle stacks that grow up & down. */
- ss.ss_sp = buf + sizeof (buf) / 2;
- ss.ss_size = sizeof (buf) / 4;
- if (sigaltstack (&ss, NULL) < 0)
- {
- printf ("second sigaltstack failed: %m\n");
- return 1;
- }
+ void *sstk2 = xalloc_sigstack (SIGSTKSZ);
/* This should fail. */
longjmp (jb, 1);
- puts ("longjmp returned and shouldn't");
- return 1;
+ xfree_sigstack(sstk1);
+ xfree_sigstack(sstk2);
+
+ FAIL_RET ("longjmp returned and shouldn't");
}
+
+#include <support/test-driver.c>
tst-longjmp_c.c test was not run at all because there was no entry for it in the Makefile. With this change, I have also included the new test-driver.c instead of test-skeleton.c. Signed-off-by: Nisha Poyarekar <nisha.s.menon@gmail.com> --- Made changes as per your suggestion and used xalloc_sigstack. debug/Makefile | 1 + debug/tst-longjmp_chk3.c | 35 ++++++++++++----------------------- 2 files changed, 13 insertions(+), 23 deletions(-)