pg.ddx.io  pgbouncer/pgbouncer GitHub issues and pull requests  
help / color / mirror / Atom feed
From: petere (@petere) <noreply+petere@github.com>
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
Subject: [pgbouncer/pgbouncer] PR #1714: Fix build with OpenSSL 4.0
Date: Fri, 20 Nov 2026 09:15:52 +0000
Message-ID: <gh-pgbouncer-pgbouncer-1714@github.com> (raw)

OpenSSL 4.0 changed X509_get_subject_name(), X509_get_issuer_name(), X509_NAME_get_entry(), and X509_NAME_ENTRY_get_data() to return const pointers, which breaks the build with -Werror (seen on the MSYS2 CI job).  Add const qualifiers to the affected variables and function parameters.  We only read through these pointers anyway.

Older OpenSSL versions don't accept const pointers in all the functions we pass these on to (some only since 1.1.0, some only since 3.0), so add wrappers in tls_compat.h that cast away const there.

inline patch 1: lib/usual/tls/tls_cert.c, lib/usual/tls/tls_compat.h, lib/usual/tls/tls_conninfo.c and 2 more (+29/-11 lines) download inline-1.patchdiff --git a/lib/usual/tls/tls_cert.c b/lib/usual/tls/tls_cert.c index e980e2441717..469266e30177 100644 --- a/lib/usual/tls/tls_cert.c +++ b/lib/usual/tls/tls_cert.c @@ -119,7 +119,7 @@ static int check_invalid_bytes(struct tls *ctx, const unsigned char *data, unsig return -1; } -static int tls_parse_asn1string(struct tls *ctx, ASN1_STRING *a1str, const char **dst_p, int minchars, int maxchars, const char *desc) +static int tls_parse_asn1string(struct tls *ctx, const ASN1_STRING *a1str, const char **dst_p, int minchars, int maxchars, const char *desc) { int format, len, ret = -1; const unsigned char *data; @@ -214,11 +214,11 @@ static int tls_parse_asn1string(struct tls *ctx, ASN1_STRING *a1str, const char return ret; } -static int tls_cert_get_dname_string(struct tls *ctx, X509_NAME *name, int nid, const char **str_p, int minchars, int maxchars, const char *desc) +static int tls_cert_get_dname_string(struct tls *ctx, const X509_NAME *name, int nid, const char **str_p, int minchars, int maxchars, const char *desc) { int loc, len; - X509_NAME_ENTRY *ne; - ASN1_STRING *a1str; + const X509_NAME_ENTRY *ne; + const ASN1_STRING *a1str; *str_p = NULL; @@ -352,7 +352,7 @@ static int tls_cert_get_altnames(struct tls *ctx, struct tls_cert *cert, X509 *x return rv; } -static int tls_get_dname(struct tls *ctx, X509_NAME *name, struct tls_cert_dname *dname) +static int tls_get_dname(struct tls *ctx, const X509_NAME *name, struct tls_cert_dname *dname) { int ret; ret = tls_cert_get_dname_string(ctx, name, NID_commonName, &dname->common_name, @@ -555,7 +555,7 @@ static void check_verify_error(struct tls *ctx, struct tls_cert *cert) int tls_parse_cert(struct tls *ctx, struct tls_cert **cert_p, const char *fingerprint_algo, X509 *x509) { struct tls_cert *cert = NULL; - X509_NAME *subject, *issuer; + const X509_NAME *subject, *issuer; int ret = -1; long version; diff --git a/lib/usual/tls/tls_compat.h b/lib/usual/tls/tls_compat.h index 7013b099e003..84681624eb7c 100644 --- a/lib/usual/tls/tls_compat.h +++ b/lib/usual/tls/tls_compat.h @@ -40,7 +40,7 @@ bool get_ecdh_curve_nid(EVP_PKEY *pk, int *nid); #define X509_get_key_usage(x509) ((x509)->ex_kusage) #define X509_get_extended_key_usage(x509) ((x509)->ex_xkusage) #define SSL_CTX_get0_param(ssl_ctx) ((ssl_ctx)->param) -#define ASN1_STRING_get0_data(x) ((const unsigned char *)ASN1_STRING_data(x)) +#define ASN1_STRING_get0_data(x) ((const unsigned char *)ASN1_STRING_data((ASN1_STRING *)(x))) #define X509_OBJECT_get0_X509(x) ((x)->data.x509) #ifndef OPENSSL_VERSION @@ -93,6 +93,24 @@ static inline X509_OBJECT *X509_STORE_CTX_get_obj_by_subject(X509_STORE_CTX *ctx #endif /* OpenSSL <1.1 */ +/* + * OpenSSL 4.0 returns const pointers from X509_get_subject_name() etc. + * Older versions don't accept const pointers in all the functions we + * pass them on to, so cast away const there. + */ +#if OPENSSL_VERSION_NUMBER < 0x30000000L +#define X509_NAME_get_index_by_NID(name, nid, lastpos) X509_NAME_get_index_by_NID((X509_NAME *)(name), nid, lastpos) +#define X509_NAME_get_text_by_NID(name, nid, buf, len) X509_NAME_get_text_by_NID((X509_NAME *)(name), nid, buf, len) +#define X509_find_by_subject(sk, name) X509_find_by_subject(sk, (X509_NAME *)(name)) +#define X509_STORE_CTX_get_obj_by_subject(vs, type, name) X509_STORE_CTX_get_obj_by_subject(vs, type, (X509_NAME *)(name)) +#endif +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) +#define X509_NAME_oneline(name, buf, size) X509_NAME_oneline((X509_NAME *)(name), buf, size) +#define X509_NAME_get_entry(name, loc) X509_NAME_get_entry((X509_NAME *)(name), loc) +#define X509_NAME_ENTRY_get_data(ne) X509_NAME_ENTRY_get_data((X509_NAME_ENTRY *)(ne)) +#define ASN1_STRING_type(x) ASN1_STRING_type((ASN1_STRING *)(x)) +#endif + /* ecdh_auto is broken - ignores main EC key */ #undef SSL_CTX_set_ecdh_auto diff --git a/lib/usual/tls/tls_conninfo.c b/lib/usual/tls/tls_conninfo.c index 0a4b14e23e11..4952062a0e89 100644 --- a/lib/usual/tls/tls_conninfo.c +++ b/lib/usual/tls/tls_conninfo.c @@ -90,7 +90,7 @@ static int tls_get_peer_cert_hash(struct tls *ctx, char **hash) static int tls_get_peer_cert_issuer(struct tls *ctx, char **issuer) { - X509_NAME *name = NULL; + const X509_NAME *name = NULL; *issuer = NULL; if (ctx->ssl_peer_cert == NULL) @@ -105,7 +105,7 @@ static int tls_get_peer_cert_issuer(struct tls *ctx, char **issuer) static int tls_get_peer_cert_subject(struct tls *ctx, char **subject) { - X509_NAME *name = NULL; + const X509_NAME *name = NULL; *subject = NULL; if (ctx->ssl_peer_cert == NULL) diff --git a/lib/usual/tls/tls_ocsp.c b/lib/usual/tls/tls_ocsp.c index 8214f91966cd..69630cab0f3c 100644 --- a/lib/usual/tls/tls_ocsp.c +++ b/lib/usual/tls/tls_ocsp.c @@ -157,7 +157,7 @@ int tls_get_ocsp_info(struct tls *ctx, int *response_status, int *cert_status, static OCSP_CERTID *tls_ocsp_get_certid(X509 *main_cert, STACK_OF(X509) *extra_certs, SSL_CTX *ssl_ctx) { - X509_NAME *issuer_name; + const X509_NAME *issuer_name; X509 *issuer; X509_STORE_CTX *storectx = NULL; X509_OBJECT *tmpobj; diff --git a/lib/usual/tls/tls_verify.c b/lib/usual/tls/tls_verify.c index bfb8e142e531..f2a44da5f8c7 100644 --- a/lib/usual/tls/tls_verify.c +++ b/lib/usual/tls/tls_verify.c @@ -190,7 +190,7 @@ static int tls_check_subject_altname(struct tls *ctx, X509 *cert, const char *na static int tls_check_common_name(struct tls *ctx, X509 *cert, const char *name) { - X509_NAME *subject_name; + const X509_NAME *subject_name; char *common_name = NULL; union tls_addr addrbuf; int common_name_len;

Message-ID: <gh-pgbouncer-pgbouncer-1714@github.com>
Permalink:  ../gh-pgbouncer-pgbouncer-1714@github.com/

 ·  · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox