From 5e8ff0aae1da4d14fba2a99d02117bdcc5363a11 Mon Sep 17 00:00:00 2001 From: Junyeon LEE Date: Thu, 20 Apr 2017 16:00:02 +0900 Subject: [PATCH] net/tls: improve error handling in mbedtls_dhm_calc_secret() In case of ctx is NULL or output_size is specified less than expected, we'd rather bail out earlier without bothering with see_supported_dhm_size(). Change-Id: I222a7a997de2ce6e27d2525c86a5e6fc9557b147 Signed-off-by: Junyeon LEE --- os/net/tls/dhm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/os/net/tls/dhm.c b/os/net/tls/dhm.c index 386591a..70e77d5 100644 --- a/os/net/tls/dhm.c +++ b/os/net/tls/dhm.c @@ -388,16 +388,16 @@ int mbedtls_dhm_calc_secret(mbedtls_dhm_context *ctx, unsigned char *output, siz int ret; mbedtls_mpi GYb; + if (ctx == NULL || output_size < ctx->len) { + return (MBEDTLS_ERR_DHM_BAD_INPUT_DATA); + } + #if defined(CONFIG_HW_DH_PARAM) if (see_supported_dhm_size(ctx->len)) { return hw_calculate_dhm_secret(ctx, output, output_size, olen); } #endif - if (ctx == NULL || output_size < ctx->len) { - return (MBEDTLS_ERR_DHM_BAD_INPUT_DATA); - } - if ((ret = dhm_check_range(&ctx->GY, &ctx->P)) != 0) { return (ret); } -- 2.7.4