1 /* Copyright 2017 Yaakov Selkowitz <yselkowi@redhat.com> */ 2 #include <signal.h> 3 #include <string.h> 4 #include <unistd.h> 5 #include <stdio.h> 6 #include <stdlib.h> 7 #undef puts 8 9 static void (*fortify_handler)(int sig); 10 11 #define CHK_FAIL_MSG "*** overflow detected ***: terminated" 12 13 void 14 __attribute__((__noreturn__)) __chk_fail(void)15__chk_fail(void) 16 { 17 #ifdef TINY_STDIO 18 puts(CHK_FAIL_MSG); 19 #else 20 static const char msg[] = CHK_FAIL_MSG "\n"; 21 write (2, msg, sizeof(msg)-1); 22 #endif 23 if (fortify_handler) 24 (*fortify_handler)(SIGABRT); 25 abort(); 26 } 27 28 void set_fortify_handler(void (* handler)(int sig))29set_fortify_handler (void (*handler) (int sig)) 30 { 31 fortify_handler = handler; 32 } 33