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>
#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) {