From b36a9f1697cdcaa5ea871949d17a1b748ed8b0a2 Mon Sep 17 00:00:00 2001
From: tb <>
Date: Tue, 16 May 2023 18:41:18 +0000
Subject: ecdhtest: check malloc() return values

From Ilya Chipitsine
---
 src/regress/lib/libcrypto/ecdh/ecdhtest.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

(limited to 'src')

diff --git a/src/regress/lib/libcrypto/ecdh/ecdhtest.c b/src/regress/lib/libcrypto/ecdh/ecdhtest.c
index e6046a5400..415414bdc0 100644
--- a/src/regress/lib/libcrypto/ecdh/ecdhtest.c
+++ b/src/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;
-- 
cgit v1.2.3-55-g6feb