1 // Verify that use of longjmp() in a _FORTIFY_SOURCE'd library (without ASAN)
2 // is correctly intercepted such that the stack is unpoisoned.
3 // Note: it is essential that the external library is not built with ASAN,
4 // otherwise it would be able to unpoison the stack before use.
6 // RUN: %clang -DIS_LIBRARY -D_FORTIFY_SOURCE=2 -O2 %s -c -o %t.o
7 // RUN: %clang_asan -O2 %s %t.o -o %t
14 #include <sanitizer/asan_interface.h>
18 void external_callme(void (*callback)(void)) {
19 if (setjmp(jenv) == 0) {
24 void external_longjmp(char *msg) {
28 void external_check_stack(void) {
30 for (int i = 0; i < 256; i++) {
31 assert(!__asan_address_is_poisoned(buf + i));
36 extern void external_callme(void (*callback)(void));
37 extern void external_longjmp(char *msg);
38 extern void external_check_stack(void);
40 static void callback(void) {
41 char msg[16]; /* Note: this triggers addition of a redzone. */
42 /* Note: msg is passed to prevent compiler optimization from removing it. */
43 external_longjmp(msg);
47 external_callme(callback);
48 external_check_stack();