From 2ccfced2116d00e6ddf3aa6f10cfacab5a863c76 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 27 Sep 2023 21:52:06 +0200 Subject: Add an option to make use of compiler-provided _chk builtins --- include/stdio.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/stdio.h') diff --git a/include/stdio.h b/include/stdio.h index 582be4f..25e7ad2 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -145,11 +145,15 @@ __diagnose_as_builtin(__builtin_vsnprintf, 1, 2, 3, 4) _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n, const char *__f, __builtin_va_list __v) { +#if __has_builtin(__builtin___vsnprintf_chk) && USE_NATIVE_CHK + return __builtin___vsnprintf_chk(__s, __n, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v,); +#else size_t __b = __bos(__s, 0); if (__n > __b) __builtin_trap(); return __orig_vsnprintf(__s, __n, __f, __v); +#endif } __format(printf, 2, 0) @@ -161,6 +165,9 @@ __diagnose_as_builtin(__builtin_vsprintf, 1, 2, 3) _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, __builtin_va_list __v) { +#if __has_builtin(__builtin___vsnprintf_chk) && USE_NATIVE_CHK + return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v,); +#else size_t __b = __bos(__s, 0); int __r; @@ -172,8 +179,10 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, __r = __orig_vsprintf(__s, __f, __v); } return __r; +#endif } + #if __has_builtin(__builtin_va_arg_pack) /* clang is missing __builtin_va_arg_pack, so we cannot use these impls -- cgit v1.3