From: tb Date: Wed, 29 Dec 2021 22:56:25 +0000 (+0000) Subject: More return value checks for EVP_* API X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4fcd5ec7a6e3ceba1f81835863b49252436e3bef;p=openbsd More return value checks for EVP_* API CID 345159 --- diff --git a/regress/lib/libcrypto/sha256/sha256test.c b/regress/lib/libcrypto/sha256/sha256test.c index 4732611d559..dbba2abe3c5 100644 --- a/regress/lib/libcrypto/sha256/sha256test.c +++ b/regress/lib/libcrypto/sha256/sha256test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sha256test.c,v 1.6 2021/12/04 07:58:10 tb Exp $ */ +/* $OpenBSD: sha256test.c,v 1.7 2021/12/29 22:56:25 tb Exp $ */ /* ==================================================================== * Copyright (c) 2004 The OpenSSL Project. All rights reserved. * ==================================================================== @@ -96,17 +96,22 @@ main(int argc, char **argv) { fprintf(stderr, "\nEVP_MD_CTX_new() failed.\n"); goto err; } - EVP_DigestInit_ex(evp, EVP_sha256(), NULL); - for (i = 0; i < 1000000; i += 160) - EVP_DigestUpdate(evp, + if (!EVP_DigestInit_ex(evp, EVP_sha256(), NULL)) + goto err; + for (i = 0; i < 1000000; i += 160) { + if (!EVP_DigestUpdate(evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", - (1000000 - i) < 160 ? 1000000 - i : 160); - EVP_DigestFinal_ex(evp, md, NULL); - EVP_MD_CTX_reset(evp); + (1000000 - i) < 160 ? 1000000 - i : 160)) + goto err; + } + if (!EVP_DigestFinal_ex(evp, md, NULL)) + goto err; + if (!EVP_MD_CTX_reset(evp)) + goto err; if (memcmp(md, app_b3, sizeof(app_b3))) { fflush(stdout); @@ -120,7 +125,8 @@ main(int argc, char **argv) { fprintf(stdout, "Testing SHA-224 "); - EVP_Digest ("abc",3,md,NULL,EVP_sha224(),NULL); + if (!EVP_Digest("abc",3,md,NULL,EVP_sha224(),NULL)) + goto err; if (memcmp(md, addenum_1, sizeof(addenum_1))) { fflush(stdout); fprintf(stderr, "\nTEST 1 of 3 failed.\n"); @@ -129,10 +135,11 @@ main(int argc, char **argv) { fprintf(stdout, "."); fflush(stdout); - EVP_Digest( + if (!EVP_Digest( "abcdbcde""cdefdefg""efghfghi""ghijhijk" "ijkljklm""klmnlmno""mnopnopq", - 56, md, NULL, EVP_sha224(), NULL); + 56, md, NULL, EVP_sha224(), NULL)) + goto err; if (memcmp(md, addenum_2, sizeof(addenum_2))) { fflush(stdout); fprintf(stderr, "\nTEST 2 of 3 failed.\n"); @@ -141,14 +148,19 @@ main(int argc, char **argv) { fprintf(stdout, "."); fflush(stdout); - EVP_DigestInit_ex (evp, EVP_sha224(), NULL); - for (i = 0; i < 1000000; i += 64) - EVP_DigestUpdate(evp, + if (!EVP_DigestInit_ex (evp, EVP_sha224(), NULL)) + goto err; + for (i = 0; i < 1000000; i += 64) { + if (!EVP_DigestUpdate(evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", - (1000000 - i) < 64 ? 1000000 - i : 64); - EVP_DigestFinal_ex(evp, md, NULL); - EVP_MD_CTX_reset(evp); + (1000000 - i) < 64 ? 1000000 - i : 64)) + goto err; + } + if (!EVP_DigestFinal_ex(evp, md, NULL)) + goto err; + if (!EVP_MD_CTX_reset(evp)) + goto err; if (memcmp(md, addenum_3, sizeof(addenum_3))) { fflush(stdout);