diff --git a/ChangeLog b/ChangeLog index 1a85af29a0..a47cdebc33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ Security * Tighten should-be-constant-time memcmp against compiler optimizations. * Ensure that buffers are cleared after use if they contain sensitive data. Changes were introduced in multiple places in the library. + * Set PEM buffer to zero before freeing it, to avoid decoded private keys + being leaked to memory after release. Bugfix * Fix memory leak in ssl_set_hostname() when called multiple times. diff --git a/library/pem.c b/library/pem.c index 789a92d511..fedbc5cbb1 100644 --- a/library/pem.c +++ b/library/pem.c @@ -393,6 +393,8 @@ int pem_read_buffer( pem_context *ctx, const char *header, const char *footer, void pem_free( pem_context *ctx ) { + if ( ctx->buf != NULL ) + polarssl_zeroize( ctx->buf, ctx->buflen ); polarssl_free( ctx->buf ); polarssl_free( ctx->info );