Add tests for buffer corruption after PEM write
Zero remaining bytes in buffer after writing PEM data and add checks to
ensure that this is the case.
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
diff --git a/library/pem.c b/library/pem.c
index 9eff10e..8c07048 100644
--- a/library/pem.c
+++ b/library/pem.c
@@ -510,6 +510,9 @@
*p++ = '\0';
*olen = p - buf;
+ /* Clean any remaining data previously written to the buffer */
+ memset( buf + *olen, 0, buf_len - *olen );
+
mbedtls_free( encode_buf );
return( 0 );
}