From 1cfba584db78929b8f3c89d8980d0620c753160a Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 21 Nov 2022 15:26:18 +0100 Subject: [PATCH] Support memset_explicit() if available NetBSD has explicit_memset(), but C23 decided to implement the same thing but call it memset_explicit() instead. Go figure. --- configure | 6 ++++++ configure.ac | 2 +- src/libsodium/sodium/utils.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 5667f078..2bdd70c3 100755 --- a/configure +++ b/configure @@ -20935,6 +20935,12 @@ if test "x$ac_cv_func_explicit_bzero" = xyes then : printf "%s\n" "#define HAVE_EXPLICIT_BZERO 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "memset_explicit" "ac_cv_func_memset_explicit" +if test "x$ac_cv_func_memset_explicit" = xyes +then : + printf "%s\n" "#define HAVE_MEMSET_EXPLICIT 1" >>confdefs.h + fi ac_fn_c_check_func "$LINENO" "explicit_memset" "ac_cv_func_explicit_memset" if test "x$ac_cv_func_explicit_memset" = xyes diff --git a/configure.ac b/configure.ac index 2183163a..b180c3d8 100644 --- a/configure.ac +++ b/configure.ac @@ -884,7 +884,7 @@ AS_IF([test "x$WASI" = "x"],[ AC_CHECK_FUNCS([posix_memalign nanosleep]) AS_IF([test "x$WASI" = "x"],[ - AC_CHECK_FUNCS([memset_s explicit_bzero explicit_memset]) + AC_CHECK_FUNCS([memset_s explicit_bzero memset_explicit explicit_memset]) ]) AC_SUBST([LIBTOOL_EXTRA_FLAGS]) diff --git a/src/libsodium/sodium/utils.c b/src/libsodium/sodium/utils.c index 09cbc909..98c9f5a6 100644 --- a/src/libsodium/sodium/utils.c +++ b/src/libsodium/sodium/utils.c @@ -129,6 +129,8 @@ sodium_memzero(void * const pnt, const size_t len) } #elif defined(HAVE_EXPLICIT_BZERO) explicit_bzero(pnt, len); +#elif defined(HAVE_MEMSET_EXPLICIT) + memset_explicit(pnt, 0, len); #elif defined(HAVE_EXPLICIT_MEMSET) explicit_memset(pnt, 0, len); #elif HAVE_WEAK_SYMBOLS