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 #include <ssp/ssp.h> 8 #undef puts 9 10 static void (*fortify_handler)(int sig); 11 12 #define CHK_FAIL_MSG "*** overflow detected ***: terminated" 13 14 _Noreturn void __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