Add support for x509 SAN RCF822 and DirectoryName for csr generation

Unify the code with the x509 crt counterpart.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
diff --git a/library/x509write_crt.c b/library/x509write_crt.c
index 59fd589..a6dc22c 100644
--- a/library/x509write_crt.c
+++ b/library/x509write_crt.c
@@ -288,6 +288,11 @@
         buf + buflen - len,
         len);
 
+    /* If we exceeded the allocated buffer it means that maximum size of the SubjectAltName list
+     * was incorrectly calculated and memory is corrupted. */
+    if (p < buf) {
+        ret = MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
+    }
 cleanup:
     mbedtls_free(buf);
     return ret;