diff options
author | schwarze <> | 2020-09-18 16:18:56 +0000 |
---|---|---|
committer | schwarze <> | 2020-09-18 16:18:56 +0000 |
commit | a4fede3dd4df29c213d7d3e5ba6b126d77af33b5 (patch) | |
tree | 22cef703eb6773ec5445f164a36eb80856fb0432 /src | |
parent | fba76a3645753641e00c78f5e5f52e3c86bd1426 (diff) | |
download | openbsd-a4fede3dd4df29c213d7d3e5ba6b126d77af33b5.tar.gz openbsd-a4fede3dd4df29c213d7d3e5ba6b126d77af33b5.tar.bz2 openbsd-a4fede3dd4df29c213d7d3e5ba6b126d77af33b5.zip |
If ssl_cert_dup() fails in SSL_set_SSL_CTX(3), return failure
rather than silently leaving a NULL pointer in ssl->cert.
Kurt Roeckx fixed the same bug similarly in OpenSSL in 2015.
While here,
(1) make the code easier to read and more robust by returning right
away when ssl still uses the context it was created from and the ctx
argument is NULL, rather than doing a lot of work that changes
nothing unless data is already corrupt, and
(2) use the shorter and more inituitive SSL_CTX_up_ref(3) rather
than manually calling CRYPTO_add(3), which means no functional
change and is also in the OpenSSL 1.1 branch.
OK tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libssl/ssl_lib.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index 73bc05e967..c184f75abe 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.229 2020/09/16 07:25:15 schwarze Exp $ */ | 1 | /* $OpenBSD: ssl_lib.c,v 1.230 2020/09/18 16:18:56 schwarze 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 | * |
@@ -2726,17 +2726,22 @@ SSL_get_SSL_CTX(const SSL *ssl) | |||
2726 | SSL_CTX * | 2726 | SSL_CTX * |
2727 | SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx) | 2727 | SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx) |
2728 | { | 2728 | { |
2729 | if (ssl->ctx == ctx) | 2729 | CERT *new_cert; |
2730 | return (ssl->ctx); | 2730 | |
2731 | if (ctx == NULL) | 2731 | if (ctx == NULL) |
2732 | ctx = ssl->initial_ctx; | 2732 | ctx = ssl->initial_ctx; |
2733 | if (ssl->ctx == ctx) | ||
2734 | return (ssl->ctx); | ||
2733 | 2735 | ||
2736 | if ((new_cert = ssl_cert_dup(ctx->internal->cert)) == NULL) | ||
2737 | return NULL; | ||
2734 | ssl_cert_free(ssl->cert); | 2738 | ssl_cert_free(ssl->cert); |
2735 | ssl->cert = ssl_cert_dup(ctx->internal->cert); | 2739 | ssl->cert = new_cert; |
2736 | 2740 | ||
2737 | CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX); | 2741 | SSL_CTX_up_ref(ctx); |
2738 | SSL_CTX_free(ssl->ctx); /* decrement reference count */ | 2742 | SSL_CTX_free(ssl->ctx); /* decrement reference count */ |
2739 | ssl->ctx = ctx; | 2743 | ssl->ctx = ctx; |
2744 | |||
2740 | return (ssl->ctx); | 2745 | return (ssl->ctx); |
2741 | } | 2746 | } |
2742 | 2747 | ||