[PATCH] Require a declaration before using explicit_bzero

From: "Timo J(dot) Rinne" <tr-pg(at)rinne(dot)mobi>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: [PATCH] Require a declaration before using explicit_bzero
Date: 2026-07-20 15:00:20
Message-ID: 6677375ded2a48eb1fd29accbb59e504@rinne.mobi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I was doing some research about adding native SHA3 support to PostgreSQL
(to be discussed another day) and encountered a compilation failure with
LibreSSL 3.7.2 on macOS/arm64. The compilation failure is caused by
explicit_bzero symbo that exported by the library, but not declared by
the public headers. The existing configure check only determines whether
the symbol can be linked. Because libcrypto is already present in LIBS,
that check succeeds and HAVE_EXPLICIT_BZERO is defined.

PostgreSQL then assumes that the function is also declared and
suppresses the declaration of its fallback implementation in port.h.
Code using explicit_bzero, such as cryptohash_openssl.c, consequently
fails to compile because no prototype is visible.

The attached patch checks separately whether explicit_bzero is declared
by <string.h>. If it is not declared, PostgreSQL uses its own
src/port/explicit_bzero.c implementation, regardless of whether a linked
library happens to export an undeclared symbol. If it is declared, the
existing function-availability check is retained. Equivalent logic is
included for both Autoconf and Meson builds.

This avoids depending on what is effectively an incidental, non-public
LibreSSL export while preserving the existing behavior on platforms
where explicit_bzero is part of the public system interface.

This patch is intended for application to master and is attached as
pg-explicit-bzero-declaration.patch.

I tested it with LibreSSL 3.7.2 using both Autoconf and Meson. The full
builds completed successfully, and the Autoconf build passed all 245
core regression tests. All tests enabled in the Meson configuration
passed; TAP-only tests were not enabled in that configuration.

I also tested full Autoconf and Meson builds on Debian Bookworm with
glibc 2.36. There, explicit_bzero is both declared and available, and
PostgreSQL correctly continued to use the system implementation. A
normal macOS build against Homebrew OpenSSL 3.6.3 also completed
successfully.

The change is not platform-specific and introduces no user-visible
interface or expected performance change.

Regards,
--
Timo J. Rinne <tri(at)iki(dot)fi>

Attachment Content-Type Size
pg-explicit-bzero-declaration.patch text/x-diff 4.6 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-07-20 15:13:24 Re: [PATCH] Add pg_get_event_trigger_ddl() function
Previous Message Tomas Vondra 2026-07-20 14:57:14 Re: read stream: Backward I/O combining