From 3067c28ceb744b2bafe9202023084f762871e844 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 27 Sep 2023 23:28:50 +0200 Subject: Add `printf` hardening --- include/stdio.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/stdio.h') diff --git a/include/stdio.h b/include/stdio.h index b407d0f..c363edc 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -38,6 +38,7 @@ extern "C" { #undef popen #undef vsnprintf #undef vsprintf +#undef printf __access(read_only, 2) #if __has_builtin(__builtin_fdopen) @@ -241,6 +242,17 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) #endif } +__format(printf, 1, 2) +__access(read_only, 1) +_FORTIFY_FN(printf) int printf(const char *__f, ...) +{ +#if __has_builtin(__builtin___printf_chk) && USE_NATIVE_CHK + return __builtin___printf_chk(_FORTIFY_SOURCE, __f, __builtin_va_arg_pack()); +#else + return __orig_printf(__f, __builtin_va_arg_pack()); +#endif +} + #endif /* __has_builtin(__builtin_va_arg_pack) */ #ifdef __cplusplus -- cgit v1.3