]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: ssl: fix ALPN/NPN loss on duplicated crt-list ssl configs
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 1 Dec 2026 10:08:57 +0000 (10:08 +0000)
committerWilliam Lallemand <wlallemand@haproxy.com>
Tue, 1 Dec 2026 10:18:27 +0000 (11:18 +0100)
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 <dmnk@google.com>
src/ssl_crtlist.c

index b0885abf61dc2a2e19f95cf2e0341e2536a3a7f9..023f8ebc9e7f8631c0ce5660d711e7f53b7c8363 100644 (file)
@@ -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) {