From e23a57ad43f82d861aecc37e5a3bb3a35a5f0e31 Mon Sep 17 00:00:00 2001 From: Ben Taylor Date: Fri, 1 May 2026 13:55:30 +0100 Subject: [PATCH] Add fix for empty digestAlgorithm Signed-off-by: Ben Taylor --- library/pkcs7.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/pkcs7.c b/library/pkcs7.c index 2cc7812bf0..61e9ee9754 100644 --- a/library/pkcs7.c +++ b/library/pkcs7.c @@ -142,6 +142,10 @@ static int pkcs7_get_digest_algorithm_set(unsigned char **p, return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PKCS7_INVALID_ALG, ret); } + if (len == 0) { + return 0; + } + end = *p + len; ret = mbedtls_asn1_get_alg_null(p, end, alg); @@ -481,9 +485,11 @@ static int pkcs7_get_signed_data(unsigned char *buf, size_t buflen, return ret; } - ret = mbedtls_x509_oid_get_md_alg(&signed_data->digest_alg_identifiers, &md_alg); - if (ret != 0) { - return MBEDTLS_ERR_PKCS7_INVALID_ALG; + if (signed_data->digest_alg_identifiers.p != NULL) { + ret = mbedtls_x509_oid_get_md_alg(&signed_data->digest_alg_identifiers, &md_alg); + if (ret != 0) { + return MBEDTLS_ERR_PKCS7_INVALID_ALG; + } } mbedtls_pkcs7_buf content_type;