diff --git a/lib/libc/newlib/libc-hooks.c b/lib/libc/newlib/libc-hooks.c index 43aa566dc76..2b63292ba2f 100644 --- a/lib/libc/newlib/libc-hooks.c +++ b/lib/libc/newlib/libc-hooks.c @@ -275,6 +275,18 @@ __weak int *__errno(void) return z_errno(); } +/* This function gets called if static buffer overflow detection is enabled + * on stdlib side (Newlib here), in case such an overflow is detected. Newlib + * provides an implementation not suitable for us, so we override it here. + */ +__weak FUNC_NORETURN void __chk_fail(void) +{ + static const char chk_fail_msg[] = "* buffer overflow detected *\n"; + _write(2, chk_fail_msg, sizeof(chk_fail_msg) - 1); + k_oops(); + CODE_UNREACHABLE; +} + #if CONFIG_XTENSA extern int _read(int fd, char *buf, int nbytes); extern int _open(const char *name, int mode);