From c09b379f4198ce3a9faf7389bbb220ce647379e1 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 6 May 2021 14:25:51 +0200 Subject: [PATCH] TT#111150 Add an alternative implementation for taint_func When the compiler does not have support for the __error__ attribute, fallback to use the GCC posion pragma, which works on both gcc and clang. It ha the advantage of being more portable and working at the preprocessor level, which means is not affected by symbol redirection due to builtin conversion or stack-protector remapping, at the cost of worse diagnostics. Change-Id: I322396f8a0d1b993637e8aca27f27f6868ecba3c Warned-by: clang-12 --- include/aux.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/aux.h b/include/aux.h index 52583e106..df1a0e926 100644 --- a/include/aux.h +++ b/include/aux.h @@ -244,8 +244,17 @@ INLINE int rlim(int res, rlim_t val) { /*** TAINT FUNCTIONS ***/ +#if __has_attribute(__error__) +/* This is not supported in clang, and on gcc it might become inert if the + * symbol gets remapped to a builtin or stack protected function, but it + * otherwise gives better diagnostics. */ #define taint_func(symbol, reason) \ __typeof__(symbol) symbol __attribute__((__error__(reason))) +#else +#define taint_pragma(str) _Pragma(#str) +#define taint_pragma_expand(str) taint_pragma(str) +#define taint_func(symbol, reason) taint_pragma_expand(GCC poison symbol) +#endif taint_func(rand, "use ssl_random() instead"); taint_func(random, "use ssl_random() instead");