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;