From 8928883477ff32cbbb97ee0e871324812e3b5c96 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Sun, 3 Jul 2022 11:52:44 +0200 Subject: Use explicit_bzero if available Optimizing compilers may remove the bzero call because it is followed by free. The function explicit_bzero avoids this optimization. Use it if it is available. Signed-off-by: Tobias Stoeckmann --- AuDispose.c | 4 ++++ AuRead.c | 8 ++++++++ configure.ac | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/AuDispose.c b/AuDispose.c index 355224d..b24d21c 100644 --- a/AuDispose.c +++ b/AuDispose.c @@ -38,7 +38,11 @@ XauDisposeAuth (Xauth *auth) free (auth->number); free (auth->name); if (auth->data) { +#ifdef HAVE_EXPLICIT_BZERO + (void) explicit_bzero (auth->data, auth->data_length); +#else (void) bzero (auth->data, auth->data_length); +#endif (void) free (auth->data); } free ((char *) auth); diff --git a/AuRead.c b/AuRead.c index d48906b..89430ee 100644 --- a/AuRead.c +++ b/AuRead.c @@ -56,7 +56,11 @@ read_counted_string (unsigned short *countp, char **stringp, FILE *file) if (!data) return 0; if (fread (data, sizeof (char), len, file) != len) { +#ifdef HAVE_EXPLICIT_BZERO + explicit_bzero (data, len); +#else bzero (data, len); +#endif free (data); return 0; } @@ -97,7 +101,11 @@ XauReadAuth (FILE *auth_file) free (local.number); free (local.name); if (local.data) { +#ifdef HAVE_EXPLICIT_BZERO + explicit_bzero (local.data, local.data_length); +#else bzero (local.data, local.data_length); +#endif free (local.data); } return NULL; diff --git a/configure.ac b/configure.ac index cc38e7f..47316ce 100644 --- a/configure.ac +++ b/configure.ac @@ -45,7 +45,7 @@ XORG_DEFAULT_OPTIONS AC_PROG_LN_S # Checks for library functions. -AC_CHECK_FUNCS([pathconf]) +AC_CHECK_FUNCS([explicit_bzero pathconf]) # Obtain compiler/linker options for depedencies PKG_CHECK_MODULES(XAU, xproto) -- cgit v1.2.1