[PATCH] Require a declaration before using explicit_bzero - Mailing list pgsql-hackers

From Timo J. Rinne
Subject [PATCH] Require a declaration before using explicit_bzero
Date
Msg-id 6677375ded2a48eb1fd29accbb59e504@rinne.mobi
Whole thread
List 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@iki.fi>

Attachment

pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: read stream: Backward I/O combining
Next
From: Jim Jones
Date:
Subject: Re: [PATCH] Add pg_get_event_trigger_ddl() function