libc/newlib/libc/ssp/chk_fail.c
Yaakov Selkowitz 3e8fc7d9f2 ssp: add Object Size Checking common code
The Object Size Checking (-D_FORTIFY_SOURCE=*) functionality provides
wrappers around functions suspectible to buffer overflows.  While
independent from Stack Smashing Protection (-fstack-protector*), they
are often used and implemented together.

While GCC also provides an implementation in libssp, it is completely
broken (CVE-2016-4973, RHBZ#1324759) and seemingly unfixable, as there
is no reliable way for a preprocessor macro to trigger a link flag.
Therefore, adding this here is necessary to make it work.

Note that this does require building gcc with --disable-libssp and
gcc_cv_libc_provides_ssp=yes.

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-11-29 11:25:39 -06:00

14 lines
248 B
C

#include <signal.h>
#include <string.h>
#include <unistd.h>
void
__attribute__((__noreturn__))
__chk_fail(void)
{
char msg[] = "*** buffer overflow detected ***: terminated\n";
write (2, msg, strlen (msg));
raise (SIGABRT);
_exit (127);
}