tls: don't accept NULL ALPN name in TLS_CreateInstance()

The TLS_CreateInstance() function handles a NULL alpn_name, but the
other session functions would crash if it was NULL. Change the function
to not handle the NULL for consistency and avoid potential confusion.

Fixes: 3e32e7e694 ("tls: move gnutls code into tls_gnutls.c")
This commit is contained in:
Miroslav Lichvar
2025-08-06 16:21:57 +02:00
parent 93a78c73ad
commit b365edb48e

View File

@@ -174,7 +174,7 @@ TLS_CreateInstance(int server_mode, int sock_fd, const char *server_name, const
inst->session = NULL;
inst->server = server_mode;
inst->label = Strdup(label);
inst->alpn_name = alpn_name ? Strdup(alpn_name) : NULL;
inst->alpn_name = Strdup(alpn_name);
r = gnutls_init(&inst->session, GNUTLS_NONBLOCK | GNUTLS_NO_TICKETS |
(server_mode ? GNUTLS_SERVER : GNUTLS_CLIENT));
@@ -238,9 +238,7 @@ TLS_DestroyInstance(TLS_Instance inst)
gnutls_deinit(inst->session);
Free(inst->label);
if (inst->alpn_name)
Free(inst->alpn_name);
Free(inst->alpn_name);
Free(inst);
}