summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-01-30 17:41:01 +0000
committertb <>2024-01-30 17:41:01 +0000
commit2fbdb4b0166f2045307f159118bab16fecbe9eaf (patch)
treefcd57cecbbca04066b0143b0d083d850b5252a9d /src
parentca1b3f4909994173a0d16311ece0a91761d7ecce (diff)
downloadopenbsd-2fbdb4b0166f2045307f159118bab16fecbe9eaf.tar.gz
openbsd-2fbdb4b0166f2045307f159118bab16fecbe9eaf.tar.bz2
openbsd-2fbdb4b0166f2045307f159118bab16fecbe9eaf.zip
Make EVP_{CIPHER,MD}_CTX_{cleanup,reset}() NULL-safe
We have a bunch of code that relies on this. Surely there is code out there in the wider ecosystem that relies on these being NULL-safe by now since upstream sprinkles NULL checks wherever they can. ok beck joshua
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/evp_cipher.c5
-rw-r--r--src/lib/libcrypto/evp/evp_digest.c6
2 files changed, 8 insertions, 3 deletions
diff --git a/src/lib/libcrypto/evp/evp_cipher.c b/src/lib/libcrypto/evp/evp_cipher.c
index 51bbf70654..abdc33eace 100644
--- a/src/lib/libcrypto/evp/evp_cipher.c
+++ b/src/lib/libcrypto/evp/evp_cipher.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_cipher.c,v 1.16 2024/01/07 15:21:04 tb Exp $ */ 1/* $OpenBSD: evp_cipher.c,v 1.17 2024/01/30 17:41:01 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -627,6 +627,9 @@ EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx)
627int 627int
628EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx) 628EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx)
629{ 629{
630 if (ctx == NULL)
631 return 1;
632
630 if (ctx->cipher != NULL) { 633 if (ctx->cipher != NULL) {
631 /* XXX - Avoid leaks, so ignore return value of cleanup()... */ 634 /* XXX - Avoid leaks, so ignore return value of cleanup()... */
632 if (ctx->cipher->cleanup != NULL) 635 if (ctx->cipher->cleanup != NULL)
diff --git a/src/lib/libcrypto/evp/evp_digest.c b/src/lib/libcrypto/evp/evp_digest.c
index 166b045625..9d8d94afb1 100644
--- a/src/lib/libcrypto/evp/evp_digest.c
+++ b/src/lib/libcrypto/evp/evp_digest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_digest.c,v 1.7 2023/12/29 07:22:47 tb Exp $ */ 1/* $OpenBSD: evp_digest.c,v 1.8 2024/01/30 17:41:01 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -258,10 +258,12 @@ EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
258 return EVP_MD_CTX_cleanup(ctx); 258 return EVP_MD_CTX_cleanup(ctx);
259} 259}
260 260
261/* This call frees resources associated with the context */
262int 261int
263EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) 262EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
264{ 263{
264 if (ctx == NULL)
265 return 1;
266
265 /* 267 /*
266 * Don't assume ctx->md_data was cleaned in EVP_Digest_Final, 268 * Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
267 * because sometimes only copies of the context are ever finalised. 269 * because sometimes only copies of the context are ever finalised.