diff options
author | tb <> | 2022-07-20 13:57:49 +0000 |
---|---|---|
committer | tb <> | 2022-07-20 13:57:49 +0000 |
commit | df5b87a6315647dfbae35072a0026034ebe03891 (patch) | |
tree | 15ebc0e59a4355b624daccaf387b866227e7c53f /src/lib/libssl/ssl_lib.c | |
parent | 080a39ab960b9c2cb0fe8a86d83c309d1c31ff57 (diff) | |
download | openbsd-df5b87a6315647dfbae35072a0026034ebe03891.tar.gz openbsd-df5b87a6315647dfbae35072a0026034ebe03891.tar.bz2 openbsd-df5b87a6315647dfbae35072a0026034ebe03891.zip |
Rewrite SSL{_CTX,}_set_alpn_protos() using CBS
This simplifies the freeing, assigning and copying of the passed
protocols by replacing all that code with a pair of CBS_init() and
CBS_stow(). In addition, this aligns the behavior with OpenSSL,
which no longer errors on NULL proto or 0 proto_len since 86a90dc7.
ok jsing
Diffstat (limited to 'src/lib/libssl/ssl_lib.c')
-rw-r--r-- | src/lib/libssl/ssl_lib.c | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index 860a58ddd1..08f2f74097 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.296 2022/07/17 14:49:01 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_lib.c,v 1.297 2022/07/20 13:57:49 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 | * |
@@ -1763,27 +1763,23 @@ int | |||
1763 | SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos, | 1763 | SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos, |
1764 | unsigned int protos_len) | 1764 | unsigned int protos_len) |
1765 | { | 1765 | { |
1766 | CBS cbs; | ||
1766 | int failed = 1; | 1767 | int failed = 1; |
1767 | 1768 | ||
1768 | if (protos == NULL || protos_len == 0) | 1769 | if (protos == NULL) |
1769 | goto err; | 1770 | protos_len = 0; |
1770 | 1771 | ||
1771 | free(ctx->internal->alpn_client_proto_list); | 1772 | CBS_init(&cbs, protos, protos_len); |
1772 | ctx->internal->alpn_client_proto_list = NULL; | ||
1773 | ctx->internal->alpn_client_proto_list_len = 0; | ||
1774 | 1773 | ||
1775 | if ((ctx->internal->alpn_client_proto_list = malloc(protos_len)) | 1774 | if (!CBS_stow(&cbs, &ctx->internal->alpn_client_proto_list, |
1776 | == NULL) | 1775 | &ctx->internal->alpn_client_proto_list_len)) |
1777 | goto err; | 1776 | goto err; |
1778 | ctx->internal->alpn_client_proto_list_len = protos_len; | ||
1779 | |||
1780 | memcpy(ctx->internal->alpn_client_proto_list, protos, protos_len); | ||
1781 | 1777 | ||
1782 | failed = 0; | 1778 | failed = 0; |
1783 | 1779 | ||
1784 | err: | 1780 | err: |
1785 | /* NOTE: Return values are the reverse of what you expect. */ | 1781 | /* NOTE: Return values are the reverse of what you expect. */ |
1786 | return (failed); | 1782 | return failed; |
1787 | } | 1783 | } |
1788 | 1784 | ||
1789 | /* | 1785 | /* |
@@ -1795,27 +1791,23 @@ int | |||
1795 | SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos, | 1791 | SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos, |
1796 | unsigned int protos_len) | 1792 | unsigned int protos_len) |
1797 | { | 1793 | { |
1794 | CBS cbs; | ||
1798 | int failed = 1; | 1795 | int failed = 1; |
1799 | 1796 | ||
1800 | if (protos == NULL || protos_len == 0) | 1797 | if (protos == NULL) |
1801 | goto err; | 1798 | protos_len = 0; |
1802 | 1799 | ||
1803 | free(ssl->internal->alpn_client_proto_list); | 1800 | CBS_init(&cbs, protos, protos_len); |
1804 | ssl->internal->alpn_client_proto_list = NULL; | ||
1805 | ssl->internal->alpn_client_proto_list_len = 0; | ||
1806 | 1801 | ||
1807 | if ((ssl->internal->alpn_client_proto_list = malloc(protos_len)) | 1802 | if (!CBS_stow(&cbs, &ssl->internal->alpn_client_proto_list, |
1808 | == NULL) | 1803 | &ssl->internal->alpn_client_proto_list_len)) |
1809 | goto err; | 1804 | goto err; |
1810 | ssl->internal->alpn_client_proto_list_len = protos_len; | ||
1811 | |||
1812 | memcpy(ssl->internal->alpn_client_proto_list, protos, protos_len); | ||
1813 | 1805 | ||
1814 | failed = 0; | 1806 | failed = 0; |
1815 | 1807 | ||
1816 | err: | 1808 | err: |
1817 | /* NOTE: Return values are the reverse of what you expect. */ | 1809 | /* NOTE: Return values are the reverse of what you expect. */ |
1818 | return (failed); | 1810 | return failed; |
1819 | } | 1811 | } |
1820 | 1812 | ||
1821 | /* | 1813 | /* |