]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Check for memset_explicit() and explicit_memset()
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 2 Mar 2026 06:47:42 +0000 (07:47 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 2 Mar 2026 06:51:19 +0000 (07:51 +0100)
We can use either of these to implement a missing explicit_bzero().

explicit_memset() is supported on NetBSD.  NetBSD hitherto didn't have
a way to implement explicit_bzero() other than the fallback variant.

memset_explicit() is the C23 standard, so we use it as first
preference.  It is currently supported on:

- NetBSD 11
- FreeBSD 15
- glibc 2.43

It doesn't provide additional coverage, but as it's the new standard,
its availability will presumably grow.

Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/c4701776-8d99-41da-938d-88528a3adc15%40eisentraut.org

configure
configure.ac
meson.build
src/include/pg_config.h.in
src/port/explicit_bzero.c

index a285a6ec3d705adf57b856a9d7d696322351ea32..ec4798fe5196212a1edd8d7f928150cb0f26485c 100755 (executable)
--- a/configure
+++ b/configure
@@ -15742,7 +15742,7 @@ fi
 LIBS_including_readline="$LIBS"
 LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
 
-for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton kqueue localeconv_l mbstowcs_l posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
+for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info explicit_memset getauxval getifaddrs getpeerucred inet_pton kqueue localeconv_l mbstowcs_l memset_explicit posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
index 476a76c799114c93c8668e162742bce54c278b30..b2f6fdbe6acc041f2a7012434a083244811f0c5f 100644 (file)
@@ -1841,6 +1841,7 @@ AC_CHECK_FUNCS(m4_normalize([
        copyfile
        copy_file_range
        elf_aux_info
+       explicit_memset
        getauxval
        getifaddrs
        getpeerucred
@@ -1848,6 +1849,7 @@ AC_CHECK_FUNCS(m4_normalize([
        kqueue
        localeconv_l
        mbstowcs_l
+       memset_explicit
        posix_fallocate
        ppoll
        pthread_is_threaded_np
index 5122706477d9fbec2f06a4a8ee146009acc3681d..3ee8c2325f98e522e4240b9dd62bf0cddceb336b 100644 (file)
@@ -3015,6 +3015,7 @@ func_checks = [
   ['dlsym', {'dependencies': [dl_dep], 'define': false}],
   ['elf_aux_info'],
   ['explicit_bzero'],
+  ['explicit_memset'],
   ['getauxval'],
   ['getifaddrs'],
   ['getopt', {'dependencies': [getopt_dep, gnugetopt_dep], 'skip': always_replace_getopt}],
@@ -3026,6 +3027,7 @@ func_checks = [
   ['kqueue'],
   ['localeconv_l'],
   ['mbstowcs_l'],
+  ['memset_explicit'],
   ['mkdtemp'],
   ['posix_fadvise'],
   ['posix_fallocate'],
index a0bd84376e75cf1182fcc366a376994ae51faa4f..538822cbc70566357fd63e67b924ddc79a4bcc49 100644 (file)
 /* Define to 1 if you have the `explicit_bzero' function. */
 #undef HAVE_EXPLICIT_BZERO
 
+/* Define to 1 if you have the `explicit_memset' function. */
+#undef HAVE_EXPLICIT_MEMSET
+
 /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
 #undef HAVE_FSEEKO
 
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the `memset_explicit' function. */
+#undef HAVE_MEMSET_EXPLICIT
+
 /* Define to 1 if you have the `mkdtemp' function. */
 #undef HAVE_MKDTEMP
 
index 2147fc3b315d7076f568a5e96735a964fa418c89..6be7660d28f9a4e127f3cd63f4c4b90cd65c4322 100644 (file)
 
 #include "c.h"
 
-#if HAVE_DECL_MEMSET_S
+#if defined(HAVE_MEMSET_EXPLICIT)
+
+void
+explicit_bzero(void *buf, size_t len)
+{
+       (void) memset_explicit(buf, 0, len);
+}
+
+#elif defined(HAVE_EXPLICIT_MEMSET)
+
+void
+explicit_bzero(void *buf, size_t len)
+{
+       (void) explicit_memset(buf, 0, len);
+}
+
+#elif HAVE_DECL_MEMSET_S
 
 void
 explicit_bzero(void *buf, size_t len)