From 9e323048b3f7884331f873e02c4b2286f790e9d8 Mon Sep 17 00:00:00 2001 From: Kazuho Oku Date: Tue, 7 Nov 2023 12:55:51 +0100 Subject: [PATCH] key_schedule_new might fail due to malloc failing --- lib/picotls.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/picotls.c b/lib/picotls.c index 34588cd16..b00b4292e 100644 --- a/lib/picotls.c +++ b/lib/picotls.c @@ -2373,7 +2373,10 @@ static int send_client_hello(ptls_t *tls, ptls_message_emitter_t *emitter, ptls_ /* initialize key schedule */ if (!is_second_flight) { - tls->key_schedule = key_schedule_new(tls->cipher_suite, tls->ctx->cipher_suites, tls->ech.aead != NULL); + if ((tls->key_schedule = key_schedule_new(tls->cipher_suite, tls->ctx->cipher_suites, tls->ech.aead != NULL)) == NULL) { + ret = PTLS_ERROR_NO_MEMORY; + goto Exit; + } if ((ret = key_schedule_extract(tls->key_schedule, resumption_secret)) != 0) goto Exit; } @@ -4366,7 +4369,10 @@ static int server_handle_hello(ptls_t *tls, ptls_message_emitter_t *emitter, ptl goto Exit; if (!is_second_flight) { tls->cipher_suite = cs; - tls->key_schedule = key_schedule_new(cs, NULL, 0); + if ((tls->key_schedule = key_schedule_new(cs, NULL, 0)) == NULL) { + ret = PTLS_ERROR_NO_MEMORY; + goto Exit; + } } else { if (tls->cipher_suite != cs) { ret = PTLS_ALERT_HANDSHAKE_FAILURE;