From dae916b05fa4a757f164f34f186d1baaeb4de4e0 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Fri, 13 Sep 2019 14:21:13 +0100 Subject: [PATCH] X.509: Add length consistency checks to x509_get_other_name() Signed-off-by: Andrzej Kurek --- library/x509.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/x509.c b/library/x509.c index 9e17d721c..2865c2ef1 100644 --- a/library/x509.c +++ b/library/x509.c @@ -1163,11 +1163,21 @@ static int x509_get_other_name(const mbedtls_x509_buf *subject_alt_name, return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); } + if (end != p + len) { + return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); + } + if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); } + if (end != p + len) { + return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); + } + if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OID)) != 0) { return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); }