Skip to content

Commit f10433a

Browse files
committed
Making sure that protocols array is null-terminated
1 parent 023d345 commit f10433a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/vtls/unitytls.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct ssl_backend_data {
3333
unitytls_key* pk;
3434
unitytls_tlsctx* ctx;
3535
#ifdef HAS_ALPN
36-
const char *protocols[ALPN_ENTRIES_MAX];
36+
const char *protocols[ALPN_ENTRIES_MAX + 1];
3737
#endif
3838
};
3939

@@ -461,11 +461,13 @@ static CURLcode unitytls_connect_step1(struct Curl_cfilter *cf, struct Curl_easy
461461
#ifdef HAS_ALPN
462462
if (connssl->alpn) {
463463
struct alpn_proto_buf proto;
464+
// mbedtls_ssl_conf_alpn_protocols does not clone the protocols array, which is why we need to keep it inside backend struct
464465
size_t i;
466+
DEBUGASSERT(connssl->alpn->count <= ALPN_ENTRIES_MAX);
465467
for (i = 0; i < connssl->alpn->count; ++i) {
466468
backend->protocols[i] = connssl->alpn->entries[i];
467469
}
468-
// this function does not clone the protocols array, which is why we need to keep it around
470+
backend->protocols[connssl->alpn->count] = NULL; // the protocols array must be null-terminated
469471
unitytls->unitytls_tlsctx_set_alpn_protocols(backend->ctx, &backend->protocols[0], &err);
470472
if(err.code != UNITYTLS_SUCCESS) {
471473
failf(data, "Failed setting APLN protocols: %i", err.code);

0 commit comments

Comments
 (0)