net/tls: improve error handling in mbedtls_dhm_calc_secret()
authorJunyeon LEE <junyeon2.lee@samsung.com>
Thu, 20 Apr 2017 07:00:02 +0000 (16:00 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Sat, 6 May 2017 10:51:22 +0000 (19:51 +0900)
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 <junyeon2.lee@samsung.com>
os/net/tls/dhm.c

index 386591a..70e77d5 100644 (file)
@@ -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);
        }