From 062268a7fa922f274ad76278076d8fca835613dc Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 16 May 2023 18:41:18 +0000 Subject: [PATCH] ecdhtest: check malloc() return values From Ilya Chipitsine --- regress/lib/libcrypto/ecdh/ecdhtest.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/regress/lib/libcrypto/ecdh/ecdhtest.c b/regress/lib/libcrypto/ecdh/ecdhtest.c index e6046a54004..415414bdc0c 100644 --- a/regress/lib/libcrypto/ecdh/ecdhtest.c +++ b/regress/lib/libcrypto/ecdh/ecdhtest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecdhtest.c,v 1.14 2023/04/26 09:31:12 tb Exp $ */ +/* $OpenBSD: ecdhtest.c,v 1.15 2023/05/16 18:41:18 tb Exp $ */ /* ==================================================================== * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. * @@ -146,7 +146,8 @@ test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out) (void)BIO_flush(out); alen = KDF1_SHA1_len; - abuf = malloc(alen); + if ((abuf = malloc(alen)) == NULL) + goto err; aout = ECDH_compute_key(abuf, alen, EC_KEY_get0_public_key(b), a, KDF1_SHA1); @@ -154,7 +155,8 @@ test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out) (void)BIO_flush(out); blen = KDF1_SHA1_len; - bbuf = malloc(blen); + if ((bbuf = malloc(blen)) == NULL) + goto err; bout = ECDH_compute_key(bbuf, blen, EC_KEY_get0_public_key(a), b, KDF1_SHA1); @@ -344,7 +346,8 @@ ecdh_kat(BIO *out, const char *cname, int nid, Ztmplen = ECDH_size(key1); if (Ztmplen != Zlen) goto err; - Ztmp = malloc(Ztmplen); + if ((Ztmp = malloc(Ztmplen)) == NULL) + goto err; if (!ECDH_compute_key(Ztmp, Ztmplen, EC_KEY_get0_public_key(key2), key1, 0)) goto err; -- 2.20.1