summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-07-20 14:13:13 +0000
committertb <>2022-07-20 14:13:13 +0000
commit7dfe718e143629b53ed1b8654372f3a2be32d252 (patch)
tree0da012e14c59907a6e15edfa890211733df90465 /src
parente570ac9218acd894e64a719178b58fa8f1496fe1 (diff)
downloadopenbsd-7dfe718e143629b53ed1b8654372f3a2be32d252.tar.gz
openbsd-7dfe718e143629b53ed1b8654372f3a2be32d252.tar.bz2
openbsd-7dfe718e143629b53ed1b8654372f3a2be32d252.zip
Copy alpn_client_proto_list using CBS in SSL_new()
This makes the code both shorter and safer since freeing, allocation, and copying are handled by CBS_stow() internally. ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/ssl_lib.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index c6a01faa83..02b4967076 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.298 2022/07/20 14:08:49 tb Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.299 2022/07/20 14:13:13 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -240,6 +240,7 @@ SSL *
240SSL_new(SSL_CTX *ctx) 240SSL_new(SSL_CTX *ctx)
241{ 241{
242 SSL *s; 242 SSL *s;
243 CBS cbs;
243 244
244 if (ctx == NULL) { 245 if (ctx == NULL) {
245 SSLerrorx(SSL_R_NULL_SSL_CTX); 246 SSLerrorx(SSL_R_NULL_SSL_CTX);
@@ -329,17 +330,11 @@ SSL_new(SSL_CTX *ctx)
329 ctx->internal->tlsext_supportedgroups_length; 330 ctx->internal->tlsext_supportedgroups_length;
330 } 331 }
331 332
332 if (s->ctx->internal->alpn_client_proto_list != NULL) { 333 CBS_init(&cbs, ctx->internal->alpn_client_proto_list,
333 s->internal->alpn_client_proto_list = 334 ctx->internal->alpn_client_proto_list_len);
334 malloc(s->ctx->internal->alpn_client_proto_list_len); 335 if (!CBS_stow(&cbs, &s->internal->alpn_client_proto_list,
335 if (s->internal->alpn_client_proto_list == NULL) 336 &s->internal->alpn_client_proto_list_len))
336 goto err; 337 goto err;
337 memcpy(s->internal->alpn_client_proto_list,
338 s->ctx->internal->alpn_client_proto_list,
339 s->ctx->internal->alpn_client_proto_list_len);
340 s->internal->alpn_client_proto_list_len =
341 s->ctx->internal->alpn_client_proto_list_len;
342 }
343 338
344 s->verify_result = X509_V_OK; 339 s->verify_result = X509_V_OK;
345 340