libpq OpenSSL and multithreading

Daniel Gustafsson <daniel@yesql.se>

From: Daniel Gustafsson <daniel@yesql.se>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-06-27T17:24:28Z
Lists: pgsql-hackers

Attachments

The OpenSSL code in libpq have two issues for multithreading: the verify_cb
callback use a global variable to pass back error detail state and there is one
use of strerror().

The attached fixes both, with no functional change, in order to pave the way
for multithreading:

  * Rather than using a global variable the callback use a new member in the
  Port struct for passing the string, and the Port struct is in turn passed as
  private data in the SSL object
  * The strerror call is replaced with a strerror_r call using the already
  existing errorbuffer

These were tested on OpenSSL 1.1.1 through 3.5.  Parking this in the next
commitfest.

--
Daniel Gustafsson

Commits

  1. libpq: threadsafety for SSL certificate callback