/* Copyright 2017 Yaakov Selkowitz */ #include #include #include #include #include #include #undef puts static void (*fortify_handler)(int sig); #define CHK_FAIL_MSG "*** overflow detected ***: terminated" _Noreturn void __chk_fail(void) { #ifdef TINY_STDIO puts(CHK_FAIL_MSG); #else static const char msg[] = CHK_FAIL_MSG "\n"; write (2, msg, sizeof(msg)-1); #endif if (fortify_handler) (*fortify_handler)(SIGABRT); abort(); } void set_fortify_handler (void (*handler) (int sig)) { fortify_handler = handler; }