Avoid allocating empty buffers when handling length-0 CRTs
diff --git a/library/x509_crt.c b/library/x509_crt.c
index 75ea5e6..5834a4c 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -1445,7 +1445,11 @@
     }
     else
     {
-        crt->raw.p = mbedtls_calloc( 1, buflen );
+        /* Call mbedtls_calloc with buflen + 1 in order to avoid potential
+         * return of NULL in case of length 0 certificates, which we want
+         * to cleanly fail with MBEDTLS_ERR_X509_INVALID_FORMAT in the
+         * core parsing routine, but not here. */
+        crt->raw.p = mbedtls_calloc( 1, buflen + 1 );
         if( crt->raw.p == NULL )
             return( MBEDTLS_ERR_X509_ALLOC_FAILED );
         crt->raw.len = buflen;