From c8bdf36a728989cab1b81f0dbcd856f75ea4fdda Mon Sep 17 00:00:00 2001 From: Mateusz Starzyk Date: Wed, 28 Jul 2021 15:39:51 +0200 Subject: [PATCH] Validate tag pointer in ccm function. Signed-off-by: Mateusz Starzyk --- library/ccm.c | 3 ++- tests/suites/test_suite_ccm.function | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/library/ccm.c b/library/ccm.c index a14e025de..af26de8d4 100644 --- a/library/ccm.c +++ b/library/ccm.c @@ -478,7 +478,8 @@ int mbedtls_ccm_finish( mbedtls_ccm_context *ctx, ret = mbedtls_ccm_crypt( ctx, 0, 16, ctx->y, ctx->y ); if( ret != 0 ) return ret; - memcpy( tag, ctx->y, tag_len ); + if( tag != NULL ) + memcpy( tag, ctx->y, tag_len ); mbedtls_ccm_clear_state(ctx); return( 0 ); diff --git a/tests/suites/test_suite_ccm.function b/tests/suites/test_suite_ccm.function index 25cc49b8d..21f0699b4 100644 --- a/tests/suites/test_suite_ccm.function +++ b/tests/suites/test_suite_ccm.function @@ -48,10 +48,7 @@ static int check_multipart( mbedtls_ccm_context *ctx, mbedtls_free( output ); output = NULL; - if( tag->len == 0 ) - ASSERT_ALLOC( output, 16 ); - else - ASSERT_ALLOC( output, tag->len ); + ASSERT_ALLOC( output, tag->len ); TEST_EQUAL( 0, mbedtls_ccm_finish( ctx, output, tag->len ) ); ASSERT_COMPARE( output, tag->len, tag->x, tag->len ); mbedtls_free( output );