string: Disable stack protector for memset in early static initialization
[glibc.git] / debug / tst-longjmp_chk.c
blob37f858606be4c4a22dbb648cddf24d471dfbdd84
1 /* Basic test to make sure doing a longjmp to a jmpbuf with an invalid sp
2 is caught by the fortification code. */
3 #include <errno.h>
4 #include <fcntl.h>
5 #include <paths.h>
6 #include <setjmp.h>
7 #include <signal.h>
8 #include <stdbool.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
13 #include <support/support.h>
15 static jmp_buf b;
18 static void
19 __attribute__ ((noinline))
20 f (void)
22 char buf[1000];
23 asm volatile ("" : "=m" (buf));
25 if (setjmp (b) != 0)
27 puts ("second longjmp succeeded");
28 exit (1);
33 static bool expected_to_fail;
36 static void
37 handler (int sig)
39 if (expected_to_fail)
40 _exit (0);
41 else
43 static const char msg[] = "unexpected longjmp failure\n";
44 TEMP_FAILURE_RETRY (write (STDOUT_FILENO, msg, sizeof (msg) - 1));
45 _exit (1);
50 static int
51 do_test (void)
53 set_fortify_handler (handler);
56 expected_to_fail = false;
58 if (setjmp (b) == 0)
60 longjmp (b, 1);
61 /* NOTREACHED */
62 printf ("first longjmp returned\n");
63 return 1;
67 expected_to_fail = true;
69 f ();
70 longjmp (b, 1);
72 puts ("second longjmp returned");
73 return 1;
76 #include <support/test-driver.c>