summaryrefslogtreecommitdiff
path: root/usr.bin/openssl
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-03-25 10:16:03 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-03-25 10:16:03 +0000
commit280dc83ab174da6e14be70fdfa7d4570e42a064b (patch)
tree8d5baf5989e2e4c2267762eaeb91b1c0093d59c9 /usr.bin/openssl
parentb3ccf9d0a29906dc97490d62bba7b9e8d90b3568 (diff)
Clean up create_digest()
The ts code is its own kind of special. I only sent this diff out to hear beck squeal. This diff doesn't actually fix anything, apart from (maybe) appeasing some obscure static analyzer. It is decidedly less bad than a similar change in openssl's issue tracker. ok beck
Diffstat (limited to 'usr.bin/openssl')
-rw-r--r--usr.bin/openssl/ts.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/usr.bin/openssl/ts.c b/usr.bin/openssl/ts.c
index c62f1dd6b51..dfcf5dd923f 100644
--- a/usr.bin/openssl/ts.c
+++ b/usr.bin/openssl/ts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ts.c,v 1.27 2023/11/19 09:19:54 tb Exp $ */
+/* $OpenBSD: ts.c,v 1.28 2024/03/25 10:16:02 tb Exp $ */
/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
* project 2002.
*/
@@ -676,10 +676,12 @@ create_query(BIO *data_bio, char *digest, const EVP_MD *md, const char *policy,
static int
create_digest(BIO *input, char *digest, const EVP_MD *md,
- unsigned char **md_value)
+ unsigned char **out_md_value)
{
- int md_value_len;
EVP_MD_CTX *md_ctx = NULL;
+ unsigned char *md_value = NULL;
+ int md_value_len;
+ int ret = 0;
md_value_len = EVP_MD_size(md);
if (md_value_len < 0)
@@ -690,8 +692,8 @@ create_digest(BIO *input, char *digest, const EVP_MD *md,
unsigned char buffer[4096];
int length;
- *md_value = malloc(md_value_len);
- if (*md_value == NULL)
+ md_value = malloc(md_value_len);
+ if (md_value == NULL)
goto err;
if ((md_ctx = EVP_MD_CTX_new()) == NULL)
@@ -705,31 +707,30 @@ create_digest(BIO *input, char *digest, const EVP_MD *md,
goto err;
}
- if (!EVP_DigestFinal(md_ctx, *md_value, NULL))
+ if (!EVP_DigestFinal(md_ctx, md_value, NULL))
goto err;
-
- EVP_MD_CTX_free(md_ctx);
- md_ctx = NULL;
-
} else {
/* Digest bytes are specified with digest. */
long digest_len;
- *md_value = string_to_hex(digest, &digest_len);
- if (*md_value == NULL || md_value_len != digest_len) {
- free(*md_value);
- *md_value = NULL;
+ md_value = string_to_hex(digest, &digest_len);
+ if (md_value == NULL || md_value_len != digest_len) {
BIO_printf(bio_err, "bad digest, %d bytes "
"must be specified\n", md_value_len);
goto err;
}
}
- return md_value_len;
+ *out_md_value = md_value;
+ md_value = NULL;
+
+ ret = md_value_len;
err:
+ free(md_value);
EVP_MD_CTX_free(md_ctx);
- return 0;
+
+ return ret;
}
static ASN1_INTEGER *