Skip to content

Commit

Permalink
APPS: Add missing OPENSSL_free() and combine the error handler
Browse files Browse the repository at this point in the history
Add the OPENSSL_free() in the error handler to release the "*md_value"
allocated by app_malloc(). To make the code clear and avoid possible
future errors, combine the error handler in the "err" tag.
Then, we only need to use "goto err" instead of releasing the memory
separately.

Since the EVP_MD_get_size() may return negative numbers when an error occurs,
create_query() may fail to catch the error since it only considers 0 as an
error code.

Therefore, unifying the error codes of create_digest() from non-positive
numbers to 0 is better, which also benefits future programming.

Fixes: c7235be ("RFC 3161 compliant time stamp request creation, response generation and response verification.")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #23873)

(cherry picked from commit beb8217)
  • Loading branch information
JiangJias authored and t8m committed Apr 9, 2024
1 parent c91d55d commit bde5d6f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apps/ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,18 @@ static int create_digest(BIO *input, const char *digest, const EVP_MD *md,

*md_value = OPENSSL_hexstr2buf(digest, &digest_len);
if (*md_value == NULL || md_value_len != digest_len) {
OPENSSL_free(*md_value);
*md_value = NULL;
BIO_printf(bio_err, "bad digest, %d bytes "
"must be specified\n", md_value_len);
return 0;
goto err;
}
}
rv = md_value_len;
err:
if (rv <= 0) {
OPENSSL_free(*md_value);
*md_value = NULL;
rv = 0;
}
EVP_MD_CTX_free(md_ctx);
return rv;
}
Expand Down

0 comments on commit bde5d6f

Please sign in to comment.