git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: git@vger.kernel.org
Subject: [PATCH 3/3] sha256/gcrypt: die on gcry_md_open failures
Date: Mon, 31 Jul 2023 12:08:08 +0000	[thread overview]
Message-ID: <20230731120808.1230210-4-e@80x24.org> (raw)
In-Reply-To: <20230731120808.1230210-1-e@80x24.org>

`gcry_md_open' allocates memory and must (like all allocation
functions) be checked for failure.

Signed-off-by: Eric Wong <e@80x24.org>
---
 sha256/gcrypt.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sha256/gcrypt.h b/sha256/gcrypt.h
index 1d06a778af..17a90f1052 100644
--- a/sha256/gcrypt.h
+++ b/sha256/gcrypt.h
@@ -9,7 +9,9 @@ typedef gcry_md_hd_t gcrypt_SHA256_CTX;
 
 static inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
 {
-	gcry_md_open(ctx, GCRY_MD_SHA256, 0);
+	gcry_error_t err = gcry_md_open(ctx, GCRY_MD_SHA256, 0);
+	if (err)
+		die("gcry_md_open: %s", gcry_strerror(err));
 }
 
 static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)

  parent reply	other threads:[~2023-07-31 12:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-31 12:08 [PATCH 0/3] sha256/gcrypt fixes Eric Wong
2023-07-31 12:08 ` [PATCH 1/3] sha256/gcrypt: fix build with SANITIZE=leak Eric Wong
2023-07-31 12:08 ` [PATCH 2/3] sha256/gcrypt: fix memory leak with SHA-256 repos Eric Wong
2023-07-31 12:08 ` Eric Wong [this message]
2023-07-31 15:58 ` [PATCH 0/3] sha256/gcrypt fixes Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230731120808.1230210-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).