diff mbox series

[v3,07/10] syslog: Improve fortify with clang

Message ID 20240208184622.332678-8-adhemerval.zanella@linaro.org
State New
Headers show
Series Improve fortify support with clang | expand

Commit Message

Adhemerval Zanella Feb. 8, 2024, 6:46 p.m. UTC
It improve fortify checks for syslog and vsyslog.  The compile
and runtime hecks have similar coverage as with GCC.

The syslog fortify wrapper calls the va_arg version, since clang does
not support __va_arg_pack.

Checked on aarch64, armhf, x86_64, and i686.
---
 misc/bits/syslog.h | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Carlos O'Donell Feb. 20, 2024, 10:05 p.m. UTC | #1
On 2/8/24 13:46, Adhemerval Zanella wrote:
> It improve fortify checks for syslog and vsyslog.  The compile
> and runtime hecks have similar coverage as with GCC.
> 
> The syslog fortify wrapper calls the va_arg version, since clang does
> not support __va_arg_pack.
> 

LGTM.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>

> Checked on aarch64, armhf, x86_64, and i686.
> ---
>  misc/bits/syslog.h | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/misc/bits/syslog.h b/misc/bits/syslog.h
> index aadcd42000..100b0c78cc 100644
> --- a/misc/bits/syslog.h
> +++ b/misc/bits/syslog.h
> @@ -36,6 +36,15 @@ syslog (int __pri, const char *__fmt, ...)
>  {
>    __syslog_chk (__pri, __USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
>  }
> +#elif __fortify_use_clang && defined __USE_MISC
> +__fortify_function_error_function __attribute_overloadable__ void
> +syslog (int __pri, __fortify_clang_overload_arg (const char *, , __fmt), ...)
> +{
> +  __gnuc_va_list __fortify_ap;
> +  __builtin_va_start (__fortify_ap, __fmt);
> +  __vsyslog_chk (__pri, __USE_FORTIFY_LEVEL - 1, __fmt, __fortify_ap);
> +  __builtin_va_end (__fortify_ap);
> +}

OK.

>  #elif !defined __cplusplus
>  # define syslog(pri, ...) \
>    __syslog_chk (pri, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
> @@ -43,8 +52,9 @@ syslog (int __pri, const char *__fmt, ...)
>  
>  
>  #ifdef __USE_MISC
> -__fortify_function void
> -vsyslog (int __pri, const char *__fmt, __gnuc_va_list __ap)
> +__fortify_function __attribute_overloadable__ void
> +vsyslog (int __pri, __fortify_clang_overload_arg (const char *, ,__fmt),
> +	 __gnuc_va_list __ap)

OK.

>  {
>    __vsyslog_chk (__pri,  __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
>  }
diff mbox series

Patch

diff --git a/misc/bits/syslog.h b/misc/bits/syslog.h
index aadcd42000..100b0c78cc 100644
--- a/misc/bits/syslog.h
+++ b/misc/bits/syslog.h
@@ -36,6 +36,15 @@  syslog (int __pri, const char *__fmt, ...)
 {
   __syslog_chk (__pri, __USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
 }
+#elif __fortify_use_clang && defined __USE_MISC
+__fortify_function_error_function __attribute_overloadable__ void
+syslog (int __pri, __fortify_clang_overload_arg (const char *, , __fmt), ...)
+{
+  __gnuc_va_list __fortify_ap;
+  __builtin_va_start (__fortify_ap, __fmt);
+  __vsyslog_chk (__pri, __USE_FORTIFY_LEVEL - 1, __fmt, __fortify_ap);
+  __builtin_va_end (__fortify_ap);
+}
 #elif !defined __cplusplus
 # define syslog(pri, ...) \
   __syslog_chk (pri, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
@@ -43,8 +52,9 @@  syslog (int __pri, const char *__fmt, ...)
 
 
 #ifdef __USE_MISC
-__fortify_function void
-vsyslog (int __pri, const char *__fmt, __gnuc_va_list __ap)
+__fortify_function __attribute_overloadable__ void
+vsyslog (int __pri, __fortify_clang_overload_arg (const char *, ,__fmt),
+	 __gnuc_va_list __ap)
 {
   __vsyslog_chk (__pri,  __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }