Skip to content

Commit 9b8d716

Browse files
authored
(Darwin) Fix leak on setting unsupported cipher pref (#757)
1 parent db7a1bd commit 9b8d716

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

source/darwin/secure_transport_tls_channel_handler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,14 +1071,14 @@ static void s_aws_secure_transport_ctx_destroy(struct secure_transport_ctx *secu
10711071
}
10721072

10731073
static struct aws_tls_ctx *s_tls_ctx_new(struct aws_allocator *alloc, const struct aws_tls_ctx_options *options) {
1074-
struct secure_transport_ctx *secure_transport_ctx = aws_mem_calloc(alloc, 1, sizeof(struct secure_transport_ctx));
1075-
10761074
if (!aws_tls_is_cipher_pref_supported(options->cipher_pref)) {
10771075
aws_raise_error(AWS_IO_TLS_CIPHER_PREF_UNSUPPORTED);
10781076
AWS_LOGF_ERROR(AWS_LS_IO_TLS, "static: TLS Cipher Preference is not supported: %d.", options->cipher_pref);
10791077
return NULL;
10801078
}
10811079

1080+
struct secure_transport_ctx *secure_transport_ctx = aws_mem_calloc(alloc, 1, sizeof(struct secure_transport_ctx));
1081+
10821082
secure_transport_ctx->wrapped_allocator = aws_wrapped_cf_allocator_new(alloc);
10831083
if (!secure_transport_ctx->wrapped_allocator) {
10841084
goto cleanup_secure_transport_ctx;

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ if(NOT BYO_CRYPTO)
290290
add_net_test_case(alpn_successfully_negotiates)
291291
add_net_test_case(alpn_no_protocol_message)
292292
add_net_test_case(test_ecc_cert_import)
293+
294+
add_test_case(test_tls_cipher_preference)
293295
if(NOT AWS_USE_SECITEM)
294296
# These tests require the test binary to be codesigned with an Apple Developer account with entitlements.
295297
# The entitlements also require a provisioning profile and require the binary to be run from within XCode or a

tests/tls_handler_test.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,4 +2718,31 @@ static int s_test_pkcs8_import(struct aws_allocator *allocator, void *ctx) {
27182718

27192719
AWS_TEST_CASE(test_pkcs8_import, s_test_pkcs8_import)
27202720

2721+
static int s_test_tls_cipher_preference_fn(struct aws_allocator *allocator, void *ctx) {
2722+
(void)ctx;
2723+
aws_io_library_init(allocator);
2724+
2725+
struct aws_tls_ctx_options tls_options;
2726+
aws_tls_ctx_options_init_default_client(&tls_options, allocator);
2727+
2728+
aws_tls_ctx_options_set_tls_cipher_preference(&tls_options, AWS_IO_TLS_CIPHER_PREF_TLSV1_2_2025_07);
2729+
/* Creating tls context */
2730+
struct aws_tls_ctx *tls_context = aws_tls_client_ctx_new(allocator, &tls_options);
2731+
# ifdef USE_S2N
2732+
ASSERT_NOT_NULL(tls_context);
2733+
aws_tls_ctx_release(tls_context);
2734+
# else
2735+
/* The cipher suite currently only available with S2N */
2736+
ASSERT_NULL(tls_context);
2737+
ASSERT_INT_EQUALS(AWS_IO_TLS_CIPHER_PREF_UNSUPPORTED, aws_last_error());
2738+
# endif
2739+
2740+
aws_tls_ctx_options_clean_up(&tls_options);
2741+
aws_io_library_clean_up();
2742+
2743+
return AWS_OP_SUCCESS;
2744+
}
2745+
2746+
AWS_TEST_CASE(test_tls_cipher_preference, s_test_tls_cipher_preference_fn)
2747+
27212748
#endif /* BYO_CRYPTO */

0 commit comments

Comments
 (0)