1 /* Copyright 2017 Yaakov Selkowitz <yselkowi@redhat.com> */
2 #include <signal.h>
3 #include <string.h>
4 #include <unistd.h>
5 
6 static void (*fortify_handler)(int sig);
7 
8 void
9 __attribute__((__noreturn__))
__chk_fail(void)10 __chk_fail(void)
11 {
12   char msg[] = "*** buffer overflow detected ***: terminated\n";
13   write (2, msg, strlen (msg));
14   if (fortify_handler)
15       (*fortify_handler)(SIGABRT);
16   raise (SIGABRT);
17   _exit (127);
18 }
19 
20 void
set_fortify_handler(void (* handler)(int sig))21 set_fortify_handler (void (*handler) (int sig))
22 {
23     fortify_handler = handler;
24 }
25