From: William Lallemand Date: Tue, 1 Dec 2026 10:08:57 +0000 (+0000) Subject: BUG/MINOR: ssl: fix ALPN/NPN loss on duplicated crt-list ssl configs X-Git-Url: https://git.kaiwu.me/web/%7B@url%7D?a=commitdiff_plain;h=6babd254a32915d02ab47cb0f5554594c9100687;p=haproxy.git BUG/MINOR: ssl: fix ALPN/NPN loss on duplicated crt-list ssl configs The npn_str and alpn_str buffers of a ssl_bind_conf are not plain C strings but length-prefixed wire-format buffers built by ssl_sock_parse_alpn(), where each protocol name is preceded by its length byte and the total length is kept in npn_len/alpn_len. The duplicates produced by crtlist_dup_ssl_conf() for the multi-keytype bundle emulation and for the "ssl-f-use" rules were copied with strdup() up to the first NUL byte, so any protocol name whose wire length byte is zero terminated the copy early, and npn_len and alpn_len were left to their calloc() default of 0. As a result ssl_sock_prepare_ctx() saw alpn_len == 0 and never registered the ALPN selection callback: the "alpn" and "npn" parameters of a crt-list line or of a ssl-f-use line were silently dropped for every duplicated entry, and the negotiation fell back to no ALPN. Copy the buffers with their explicit lengths and carry npn_len and alpn_len over to the duplicate, so the callback is registered and advertises the full protocol list. This must be backported to 3.4, 3.3, 3.2 and 3.1. Reported-by: Dominik Maier --- diff --git a/src/ssl_crtlist.c b/src/ssl_crtlist.c index b0885abf6..023f8ebc9 100644 --- a/src/ssl_crtlist.c +++ b/src/ssl_crtlist.c @@ -101,16 +101,20 @@ struct ssl_bind_conf *crtlist_dup_ssl_conf(struct ssl_bind_conf *src) #if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) if (src->npn_str) { - dst->npn_str = strdup(src->npn_str); + dst->npn_str = calloc(1, src->npn_len + 1); if (!dst->npn_str) goto error; + memcpy(dst->npn_str, src->npn_str, src->npn_len); + dst->npn_len = src->npn_len; } #endif #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation if (src->alpn_str) { - dst->alpn_str = strdup(src->alpn_str); + dst->alpn_str = calloc(1, src->alpn_len + 1); if (!dst->alpn_str) goto error; + memcpy(dst->alpn_str, src->alpn_str, src->alpn_len); + dst->alpn_len = src->alpn_len; } #endif if (src->ca_file) {